// Make .debug_loclists the current section.
MS->switchSection(MC->getObjectFileInfo()->getDwarfLoclistsSection());
-
- unsigned AddressSize = Unit.getOrigUnit().getAddressByteSize();
+ std::optional<uint64_t> BaseAddress;
for (const DWARFLocationExpression &LocExpression :
LinkedLocationExpression) {
if (LocExpression.Range) {
+
+ if (!BaseAddress) {
+
+ BaseAddress = LocExpression.Range->LowPC;
+
+ // Emit base address.
+ MS->emitInt8(dwarf::DW_LLE_base_address);
+ LocListsSectionSize += 1;
+ unsigned AddressSize = Unit.getOrigUnit().getAddressByteSize();
+ MS->emitIntValue(*BaseAddress, AddressSize);
+ LocListsSectionSize += AddressSize;
+ }
+
// Emit type of entry.
- MS->emitInt8(dwarf::DW_LLE_start_length);
+ MS->emitInt8(dwarf::DW_LLE_offset_pair);
LocListsSectionSize += 1;
- // Emit start address.
- MS->emitIntValue(LocExpression.Range->LowPC, AddressSize);
- LocListsSectionSize += AddressSize;
+ // Emit start offset relative to base address.
+ LocListsSectionSize +=
+ MS->emitULEB128IntValue(LocExpression.Range->LowPC - *BaseAddress);
- // Emit length of the range.
- LocListsSectionSize += MS->emitSLEB128IntValue(
- LocExpression.Range->HighPC - LocExpression.Range->LowPC);
+ // Emit end offset relative to base address.
+ LocListsSectionSize +=
+ MS->emitULEB128IntValue(LocExpression.Range->HighPC - *BaseAddress);
} else {
// Emit type of entry.
MS->emitInt8(dwarf::DW_LLE_default_location);
CHECK-NEXT: Abbrev table for offset: 0x00000000
CHECK: .debug_info contents:
-CHECK: 0x00000000: Compile Unit: length = 0x00000064, format = DWARF32, version = 0x0005, unit_type = DW_UT_compile, abbr_offset = 0x0000, addr_size = 0x08 (next unit at 0x00000068)
+CHECK: 0x00000000: Compile Unit: length = 0x00000064, format = DWARF32, version = 0x0005, unit_type = DW_UT_compile, abbr_offset = 0x0000, addr_size = 0x08
CHECK: DW_AT_ranges [DW_FORM_sec_offset] (0x[[RANGELIST_OFFSET:[0-9a-f]+]]
CHECK-NEXT: [0x[[RANGELIST_OFFSET_START:[0-9a-f]+]], 0x[[RANGELIST_OFFSET_END:[0-9a-f]+]]))
-CHECK: DW_TAG_formal_parameter [3] (0x00000033)
-CHECK-NEXT: DW_AT_location [DW_FORM_sec_offset] (0x[[LOCLIST_OFFSET:[0-9a-f]+]]:
-CHECK-NEXT: [0x[[LOCLIST_OFFSET_START:[0-9a-f]+]], 0x[[LOCLIST_OFFSET_END:[0-9a-f]+]]): [[LOCLIST_EXPR:.*]]
-CHECK-NEXT: [0x[[LOCLIST_OFFSET_START2:[0-9a-f]+]], 0x[[LOCLIST_OFFSET_END2:[0-9a-f]+]]): [[LOCLIST_EXPR2:.*]])
-
-CHECK: 0x00000068: Compile Unit: length = 0x00000072, format = DWARF32, version = 0x0004, abbr_offset = 0x0000, addr_size = 0x08 (next unit at 0x000000de)
-CHECK: DW_AT_ranges [DW_FORM_sec_offset] (0x00000000
-CHECK-NEXT: [0x00000000000200[[RANGE_OFFSET_START:[0-9a-f][0-9a-f]]], 0x00000000000200[[RANGE_OFFSET_END:[0-9a-f][0-9a-f]]]))
-CHECK: DW_TAG_formal_parameter [3] (0x0000009a)
-CHECK-NEXT: DW_AT_location [DW_FORM_sec_offset] (0x[[LOC_OFFSET:[0-9a-f]+]]:
-CHECK-NEXT: [0x00000000000200[[LOC_OFFSET_START:[0-9a-f][0-9a-f]]], 0x00000000000200[[LOC_OFFSET_END:[0-9a-f][0-9a-f]]]): [[LOC_EXPR:.*]]
-CHECK-NEXT: [0x00000000000200[[LOC_OFFSET_START2:[0-9a-f][0-9a-f]]], 0x00000000000200[[LOC_OFFSET_END2:[0-9a-f][0-9a-f]]]): [[LOC_EXPR2:.*]])
+CHECK: 0x00000033: DW_TAG_subprogram [2] * (0x0000000c)
+CHECK-NEXT: DW_AT_low_pc [DW_FORM_addr] (0x[[#%.16x,LOCLIST_LOWPC:]])
+CHECK: 0x00000050: DW_TAG_formal_parameter [3] (0x00000033)
+CHECK-NEXT: DW_AT_location [DW_FORM_sec_offset] (0x[[LOCLIST_OFFSET:[0-9a-f]+]]:
+CHECK-NEXT: [0x[[#%.16x,LOCLIST_PAIR_START:]], 0x[[#%.16x,LOCLIST_PAIR_END:]]): [[LOCLIST_EXPR:.*]]
+CHECK-NEXT: [0x[[#%.16x,LOCLIST_PAIR_START2:]], 0x[[#%.16x,LOCLIST_PAIR_END2:]]): [[LOCLIST_EXPR2:.*]])
+
+CHECK: 0x00000068: Compile Unit: length = 0x00000072, format = DWARF32, version = 0x0004, abbr_offset = 0x0000, addr_size = 0x08
+CHECK: DW_AT_low_pc [DW_FORM_addr] (0x[[#%.16x,RANGE_LOWPC:]])
+CHECK-NEXT: DW_AT_ranges [DW_FORM_sec_offset] (0x00000000
+CHECK-NEXT: [0x[[#%.16x,RANGE_START:]], 0x[[#%.16x,RANGE_END:]]))
+CHECK:0x0000009a: DW_TAG_subprogram [2] * (0x00000073)
+CHECK-NEXT: DW_AT_low_pc [DW_FORM_addr] (0x[[#%.16x,LOC_LOWPC:]])
+CHECK:0x000000b7: DW_TAG_formal_parameter [3] (0x0000009a)
+CHECK-NEXT: DW_AT_location [DW_FORM_sec_offset] (0x[[LOC_OFFSET:[0-9a-f]+]]:
+CHECK-NEXT: [0x[[#%.16x,LOC_PAIR_START:]], 0x[[#%.16x,LOC_PAIR_END:]]): [[LOC_EXPR:.*]]
+CHECK-NEXT: [0x[[#%.16x,LOC_PAIR_START2:]], 0x[[#%.16x,LOC_PAIR_END2:]]): [[LOC_EXPR2:.*]])
CHECK: .debug_loc contents:
CHECK-NEXT: 0x[[LOC_OFFSET]]:
-CHECK-NEXT: (0x0000000000000000, 0x0000000000000004): [[LOC_EXPR:.*]]
-CHECK-NEXT: (0x0000000000000004, 0x0000000000000008): [[LOC_EXPR2:.*]]
+CHECK-NEXT: (0x[[#sub(LOC_PAIR_START,LOC_LOWPC)]], 0x[[#sub(LOC_PAIR_END,LOC_LOWPC)]]): [[LOC_EXPR:.*]]
+CHECK-NEXT: (0x[[#sub(LOC_PAIR_START2,LOC_LOWPC)]], 0x[[#sub(LOC_PAIR_END2,LOC_LOWPC)]]): [[LOC_EXPR2:.*]]
CHECK: .debug_loclists contents:
-CHECK-NEXT: 0x00000000: locations list header: length = 0x00000024, format = DWARF32, version = 0x0005, addr_size = 0x08, seg_size = 0x00, offset_entry_count = 0x00000000
-CHECK-NEXT: 0x[[LOCLIST_OFFSET]]:
-CHECK-NEXT: DW_LLE_start_length {{.*}}
-CHECK-NEXT: => [0x[[LOCLIST_OFFSET_START]], 0x[[LOCLIST_OFFSET_END]]): [[LOCLIST_EXPR]]
-CHECK-NEXT: DW_LLE_start_length {{.*}}
-CHECK-NEXT: => [0x[[LOCLIST_OFFSET_START2]], 0x[[LOCLIST_OFFSET_END2]]): [[LOCLIST_EXPR2]]
-CHECK-NEXT: DW_LLE_end_of_list ()
+CHECK-NEXT: 0x00000000: locations list header: length = 0x0000001f, format = DWARF32, version = 0x0005, addr_size = 0x08, seg_size = 0x00, offset_entry_count = 0x00000000
+CHECK-NEXT: 0x[[LOCLIST_OFFSET]]:
+CHECK-NEXT: DW_LLE_base_address (0x[[#LOCLIST_LOWPC]])
+CHECK-NEXT: DW_LLE_offset_pair (0x[[#sub(LOCLIST_PAIR_START,LOCLIST_LOWPC)]], 0x[[#sub(LOCLIST_PAIR_END,LOCLIST_LOWPC)]])
+CHECK-NEXT: => [0x[[#LOCLIST_PAIR_START]], 0x[[#LOCLIST_PAIR_END]]): [[LOCLIST_EXPR]]
+CHECK-NEXT: DW_LLE_offset_pair (0x[[#sub(LOCLIST_PAIR_START2,LOCLIST_LOWPC)]], 0x[[#sub(LOCLIST_PAIR_END2,LOCLIST_LOWPC)]])
+CHECK-NEXT: => [0x[[#LOCLIST_PAIR_START2]], 0x[[#LOCLIST_PAIR_END2]]): [[LOCLIST_EXPR2]]
+CHECK-NEXT: DW_LLE_end_of_list ()
CHECK: .debug_line contents:
CHECK-NEXT: debug_line[0x00000000]
CHECK-NEXT: 0x00000029: "a.cpp"
CHECK: .debug_ranges contents:
-CHECK-NEXT: 00000000 00000000000000[[RANGE_OFFSET_START]] 00000000000000[[RANGE_OFFSET_END]]
+CHECK-NEXT: 00000000 [[#sub(RANGE_START,RANGE_LOWPC)]] [[#sub(RANGE_END,RANGE_LOWPC)]]
CHECK: .debug_rnglists contents:
CHECK-NEXT: 0x00000000: range list header: length = 0x00000013, format = DWARF32, version = 0x0005, addr_size = 0x08, seg_size = 0x00, offset_entry_count = 0x00000000
CHECK-NEXT: Abbrev table for offset: 0x00000000
CHECK: .debug_info contents:
-CHECK-NEXT: 0x00000000: Compile Unit: length = 0x00000064, format = DWARF32, version = 0x0005, unit_type = DW_UT_compile, abbr_offset = 0x0000, addr_size = 0x08 (next unit at 0x00000068)
-CHECK: DW_AT_ranges [DW_FORM_sec_offset] (0x[[RANGE_OFFSET:[0-9a-f]+]]
-CHECK-NEXT: [0x[[RANGE_OFFSET_START:[0-9a-f]+]], 0x[[RANGE_OFFSET_END:[0-9a-f]+]]))
+CHECK-NEXT: 0x00000000: Compile Unit: length = 0x00000064, format = DWARF32, version = 0x0005, unit_type = DW_UT_compile, abbr_offset = 0x0000, addr_size = 0x08
+CHECK: DW_AT_ranges [DW_FORM_sec_offset] (0x[[RANGELIST_OFFSET:[0-9a-f]+]]
+CHECK-NEXT: [0x[[RANGELIST_OFFSET_START:[0-9a-f]+]], 0x[[RANGELIST_OFFSET_END:[0-9a-f]+]]))
+CHECK: 0x00000033: DW_TAG_subprogram [2] * (0x0000000c)
+CHECK-NEXT: DW_AT_low_pc [DW_FORM_addr] (0x[[#%.16x,LOCLIST_LOWPC:]])
CHECK: 0x00000050: DW_TAG_formal_parameter [3] (0x00000033)
-CHECK-NEXT: DW_AT_location [DW_FORM_sec_offset] (0x[[LOC_OFFSET:[0-9a-f]+]]:
-CHECK-NEXT: [0x[[LOC_OFFSET_START:[0-9a-f]+]], 0x[[LOC_OFFSET_END:[0-9a-f]+]]): [[LOC_EXPR:.*]]
-CHECK-NEXT: [0x[[LOC_OFFSET_START2:[0-9a-f]+]], 0x[[LOC_OFFSET_END2:[0-9a-f]+]]): [[LOC_EXPR2:.*]])
+CHECK-NEXT: DW_AT_location [DW_FORM_sec_offset] (0x[[LOC_OFFSET:[0-9a-f]+]]:
+CHECK-NEXT: [0x[[#%.16x,LOCLIST_PAIR_START:]], 0x[[#%.16x,LOCLIST_PAIR_END:]]): [[LOCLIST_EXPR:.*]]
+CHECK-NEXT: [0x[[#%.16x,LOCLIST_PAIR_START2:]], 0x[[#%.16x,LOCLIST_PAIR_END2:]]): [[LOCLIST_EXPR2:.*]])
CHECK: .debug_loclists contents:
-CHECK-NEXT: 0x00000000: locations list header: length = 0x00000024, format = DWARF32, version = 0x0005, addr_size = 0x08, seg_size = 0x00, offset_entry_count = 0x00000000
-CHECK-NEXT: 0x[[LOC_OFFSET]]:
-CHECK-NEXT: DW_LLE_start_length {{.*}}
-CHECK-NEXT: => [0x[[LOC_OFFSET_START]], 0x[[LOC_OFFSET_END]]): [[LOC_EXPR]]
-CHECK-NEXT: DW_LLE_start_length {{.*}}
-CHECK-NEXT: => [0x[[LOC_OFFSET_START2]], 0x[[LOC_OFFSET_END2]]): [[LOC_EXPR2]]
-CHECK-NEXT: DW_LLE_end_of_list ()
+CHECK-NEXT: locations list header: length = 0x0000001f, format = DWARF32, version = 0x0005, addr_size = 0x08, seg_size = 0x00, offset_entry_count = 0x00000000
+CHECK-NEXT: 0x[[LOC_OFFSET]]:
+CHECK-NEXT: DW_LLE_base_address (0x[[#LOCLIST_LOWPC]])
+CHECK-NEXT: DW_LLE_offset_pair (0x[[#sub(LOCLIST_PAIR_START,LOCLIST_LOWPC)]], 0x[[#sub(LOCLIST_PAIR_END,LOCLIST_LOWPC)]])
+CHECK-NEXT: => [0x[[#LOCLIST_PAIR_START]], 0x[[#LOCLIST_PAIR_END]]): [[LOCLIST_EXPR]]
+CHECK-NEXT: DW_LLE_offset_pair (0x[[#sub(LOCLIST_PAIR_START2,LOCLIST_LOWPC)]], 0x[[#sub(LOCLIST_PAIR_END2,LOCLIST_LOWPC)]])
+CHECK-NEXT: => [0x[[#LOCLIST_PAIR_START2]], 0x[[#LOCLIST_PAIR_END2]]): [[LOCLIST_EXPR2]]
+CHECK-NEXT: DW_LLE_end_of_list ()
CHECK: .debug_line contents:
CHECK-NEXT: debug_line[0x00000000]
CHECK: .debug_rnglists contents:
CHECK-NEXT: 0x00000000: range list header: length = 0x00000013, format = DWARF32, version = 0x0005, addr_size = 0x08, seg_size = 0x00, offset_entry_count = 0x00000000
CHECK-NEXT: ranges:
-CHECK-NEXT: [[RANGE_OFFSET]]: [DW_RLE_start_length]: {{.*}}[0x[[RANGE_OFFSET_START]], 0x[[RANGE_OFFSET_END]])
+CHECK-NEXT: [[RANGELIST_OFFSET]]: [DW_RLE_start_length]: {{.*}}[0x[[RANGELIST_OFFSET_START]], 0x[[RANGELIST_OFFSET_END]])
CHECK: .debug_names contents:
CHECK-NEX:T Name Index @ 0x0 {
#DWARF-CHECK: [0x0000000100000fa3, 0x0000000100000fbc): DW_OP_breg6 RBP-20)
#DWARF-CHECK: DW_AT_name {{.*}} "argv"
#DWARF-CHECK: DW_TAG_formal_parameter
-#DWARF-CHECK: DW_AT_location [DW_FORM_sec_offset] (0x0000004a:
+#DWARF-CHECK: DW_AT_location [DW_FORM_sec_offset] (0x00000030:
#DWARF-CHECK: [0x0000000100000f70, 0x0000000100000f89): DW_OP_reg4 RSI
#DWARF-CHECK: [0x0000000100000f89, 0x0000000100000fbc): DW_OP_entry_value(DW_OP_reg4 RSI), DW_OP_stack_value)
#DWARF-CHECK: DW_AT_name {{.*}} "argc"
#DWARF-CHECK: .debug_loclists contents:
-#DWARF-CHECK: 0x00000000: locations list header: length = 0x00000062, format = DWARF32, version = 0x0005, addr_size = 0x08, seg_size = 0x00, offset_entry_count = 0x00000000
+#DWARF-CHECK: 0x00000000: locations list header: length = 0x00000043, format = DWARF32, version = 0x0005, addr_size = 0x08, seg_size = 0x00, offset_entry_count = 0x00000000
#DWARF-CHECK: 0x0000000c:
-#DWARF-CHECK: DW_LLE_start_length (0x0000000100000f70, 0x0000000000000017)
-#DWARF-CHECK: => [0x0000000100000f70, 0x0000000100000f87): DW_OP_reg5 RDI
-#DWARF-CHECK: DW_LLE_start_length (0x0000000100000f87, 0x000000000000000c)
-#DWARF-CHECK: => [0x0000000100000f87, 0x0000000100000f93): DW_OP_reg3 RBX
-#DWARF-CHECK: DW_LLE_start_length (0x0000000100000f93, 0x000000000000000a)
-#DWARF-CHECK: => [0x0000000100000f93, 0x0000000100000f9d): DW_OP_reg4 RSI
-#DWARF-CHECK: DW_LLE_start_length (0x0000000100000fa0, 0x0000000000000003)
-#DWARF-CHECK: => [0x0000000100000fa0, 0x0000000100000fa3): DW_OP_reg3 RBX
-#DWARF-CHECK: DW_LLE_start_length (0x0000000100000fa3, 0x0000000000000019)
-#DWARF-CHECK: => [0x0000000100000fa3, 0x0000000100000fbc): DW_OP_breg6 RBP-20
-#DWARF-CHECK: DW_LLE_end_of_list ()
-#DWARF-CHECK: 0x0000004a:
-#DWARF-CHECK: DW_LLE_start_length (0x0000000100000f70, 0x0000000000000019)
-#DWARF-CHECK: => [0x0000000100000f70, 0x0000000100000f89): DW_OP_reg4 RSI
-#DWARF-CHECK: DW_LLE_start_length (0x0000000100000f89, 0x0000000000000033)
-#DWARF-CHECK: => [0x0000000100000f89, 0x0000000100000fbc): DW_OP_entry_value(DW_OP_reg4 RSI), DW_OP_stack_value
-#DWARF-CHECK: DW_LLE_end_of_list ()
+#DWARF-CHECK: DW_LLE_base_address (0x0000000100000f70)
+#DWARF-CHECK: DW_LLE_offset_pair (0x0000000000000000, 0x0000000000000017)
+#DWARF-CHECK: => [0x0000000100000f70, 0x0000000100000f87): DW_OP_reg5 RDI
+#DWARF-CHECK: DW_LLE_offset_pair (0x0000000000000017, 0x0000000000000023)
+#DWARF-CHECK: => [0x0000000100000f87, 0x0000000100000f93): DW_OP_reg3 RBX
+#DWARF-CHECK: DW_LLE_offset_pair (0x0000000000000023, 0x000000000000002d)
+#DWARF-CHECK: => [0x0000000100000f93, 0x0000000100000f9d): DW_OP_reg4 RSI
+#DWARF-CHECK: DW_LLE_offset_pair (0x0000000000000030, 0x0000000000000033)
+#DWARF-CHECK: => [0x0000000100000fa0, 0x0000000100000fa3): DW_OP_reg3 RBX
+#DWARF-CHECK: DW_LLE_offset_pair (0x0000000000000033, 0x000000000000004c)
+#DWARF-CHECK: => [0x0000000100000fa3, 0x0000000100000fbc): DW_OP_breg6 RBP-20
+#DWARF-CHECK: DW_LLE_end_of_list ()
+#DWARF-CHECK: 0x00000030:
+#DWARF-CHECK: DW_LLE_base_address (0x0000000100000f70)
+#DWARF-CHECK: DW_LLE_offset_pair (0x0000000000000000, 0x0000000000000019)
+#DWARF-CHECK: => [0x0000000100000f70, 0x0000000100000f89): DW_OP_reg4 RSI
+#DWARF-CHECK: DW_LLE_offset_pair (0x0000000000000019, 0x000000000000004c)
+#DWARF-CHECK: => [0x0000000100000f89, 0x0000000100000fbc): DW_OP_entry_value(DW_OP_reg4 RSI), DW_OP_stack_value
+#DWARF-CHECK: DW_LLE_end_of_list ()
+
+
+
+
#UPD-DWARF-CHECK: DW_TAG_compile_unit
#UPD-DWARF-CHECK: DW_AT_name {{.*}} "dwarf5-loclists.c"
#DWARF-CHECK: DW_AT_location [DW_FORM_sec_offset] (0x0000000c:
#DWARF-CHECK: [0x0000000000001130, 0x0000000000001140): DW_OP_reg5 RDI)
#DWARF-CHECK: DW_AT_name {{.*}}"var2"
-#DWARF-CHECK: DW_AT_location [DW_FORM_sec_offset] (0x00000019:
+#DWARF-CHECK: DW_AT_location [DW_FORM_sec_offset] (0x0000001b:
#DWARF-CHECK: <default>: DW_OP_reg5 RDI)
#DWARF-CHECK: DW_TAG_variable
#DWARF-CHECK: DW_AT_name {{.*}}"var3"
-#DWARF-CHECK: DW_AT_location [DW_FORM_sec_offset] (0x0000001d:
+#DWARF-CHECK: DW_AT_location [DW_FORM_sec_offset] (0x0000001f:
#DWARF-CHECK: [0x0000000000001140, 0x0000000000001150): DW_OP_reg5 RDI
#DWARF-CHECK: [0x0000000000001160, 0x0000000000001170): DW_OP_reg6 RBP)