Skip to content

Commit 9f5bd89

Browse files
committed
use CU local refs where possible
1 parent ec4f795 commit 9f5bd89

File tree

2 files changed

+37
-29
lines changed

2 files changed

+37
-29
lines changed

substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/elf/dwarf/DwarfAbbrevSectionImpl.java

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -388,12 +388,12 @@
388388
*
389389
* <li><code>DW_AT_declaration : ....... DW_FORM_flag</code>
390390
*
391-
* <li><code>Dw_AT_object_pointer : .... DW_FORM_ref_addr</code> n.b. only for method_declaration1,
391+
* <li><code>Dw_AT_object_pointer : .... DW_FORM_ref4</code> n.b. only for method_declaration1,
392392
* points to param 0 DIE
393393
*
394394
* <li><code>DW_AT_virtuality : ........ DW_FORM_data1<code> (for override methods)
395395
*
396-
* <li><code>DW_AT_containing_type : ... DW_FORM_ref_addr</code> (for override methods)
396+
* <li><code>DW_AT_containing_type : ... DW_FORM_ref4</code> (for override methods)
397397
*
398398
* </ul>
399399
*
@@ -519,7 +519,7 @@
519519
*
520520
* <li><code>Dw_AT_byte_size : ... DW_FORM_data1</code>
521521
*
522-
* <li><code>Dw_AT_type : ........ DW_FORM_ref_addr</code>
522+
* <li><code>Dw_AT_type : ........ DW_FORM_ref4</code>
523523
*
524524
* </ul>
525525
*
@@ -529,7 +529,7 @@
529529
*
530530
* <li><code>Dw_AT_byte_size : ... DW_FORM_data1</code>
531531
*
532-
* <li><code>Dw_AT_type : ........ DW_FORM_ref_addr</code>
532+
* <li><code>Dw_AT_type : ........ DW_FORM_ref4</code>
533533
*
534534
* </ul>
535535
*
@@ -569,7 +569,7 @@
569569
*
570570
* <li><code>DW_AT_external : ........ DW_FORM_flag</code>
571571
*
572-
* <li><code>DW_AT_specification : ... DW_FORM_ref_addr</code>
572+
* <li><code>DW_AT_specification : ... DW_FORM_ref4</code>
573573
*
574574
* </ul>
575575
*
@@ -638,7 +638,7 @@
638638
* <li><code>abbrev_code == static_field_location, tag == DW_TAG_variable,
639639
* no_children</code>
640640
*
641-
* <li><code>DW_AT_specification : ... DW_FORM_ref_addr</code>
641+
* <li><code>DW_AT_specification : ... DW_FORM_ref4</code>
642642
*
643643
* <li><code>DW_AT_linkage_name : .... DW_FORM_strp</code>
644644
*
@@ -697,7 +697,7 @@
697697
*
698698
* <li><code>Dw_AT_byte_size : ... DW_FORM_data1</code>
699699
*
700-
* <li><code>Dw_AT_type : ........ DW_FORM_ref_addr</code>
700+
* <li><code>Dw_AT_type : ........ DW_FORM_ref4</code>
701701
*
702702
* </ul>
703703
*
@@ -765,7 +765,7 @@
765765
*
766766
* <li><code>Dw_AT_byte_size : ... DW_FORM_data1</code>
767767
*
768-
* <li><code>DW_AT_TYPE : ....... DW_FORM_ref_addr</code>
768+
* <li><code>DW_AT_TYPE : ....... DW_FORM_ref4</code>
769769
*
770770
* </ul>
771771
*
@@ -1060,7 +1060,7 @@ private int writeClassReferenceAbbrev(@SuppressWarnings("unused") DebugContext c
10601060
pos = writeAttrType(DwarfDebugInfo.DW_AT_byte_size, buffer, pos);
10611061
pos = writeAttrForm(DwarfDebugInfo.DW_FORM_data1, buffer, pos);
10621062
pos = writeAttrType(DwarfDebugInfo.DW_AT_type, buffer, pos);
1063-
pos = writeAttrForm(DwarfDebugInfo.DW_FORM_ref_addr, buffer, pos);
1063+
pos = writeAttrForm(DwarfDebugInfo.DW_FORM_ref4, buffer, pos);
10641064
/*
10651065
* Now terminate.
10661066
*/
@@ -1103,10 +1103,10 @@ private int writeMethodDeclarationAbbrev(@SuppressWarnings("unused") DebugContex
11031103
// pos = writeAttrType(DwarfDebugInfo.DW_AT_virtuality, buffer, pos);
11041104
// pos = writeAttrForm(DwarfDebugInfo.DW_FORM_data1, buffer, pos);
11051105
pos = writeAttrType(DwarfDebugInfo.DW_AT_containing_type, buffer, pos);
1106-
pos = writeAttrForm(DwarfDebugInfo.DW_FORM_ref_addr, buffer, pos);
1106+
pos = writeAttrForm(DwarfDebugInfo.DW_FORM_ref4, buffer, pos);
11071107
if (abbrevCode == DwarfDebugInfo.DW_ABBREV_CODE_method_declaration) {
11081108
pos = writeAttrType(DwarfDebugInfo.DW_AT_object_pointer, buffer, pos);
1109-
pos = writeAttrForm(DwarfDebugInfo.DW_FORM_ref_addr, buffer, pos);
1109+
pos = writeAttrForm(DwarfDebugInfo.DW_FORM_ref4, buffer, pos);
11101110
}
11111111
/*
11121112
* Now terminate.
@@ -1221,7 +1221,7 @@ private int writeArrayReferenceAbbrev(@SuppressWarnings("unused") DebugContext c
12211221
pos = writeAttrType(DwarfDebugInfo.DW_AT_byte_size, buffer, pos);
12221222
pos = writeAttrForm(DwarfDebugInfo.DW_FORM_data1, buffer, pos);
12231223
pos = writeAttrType(DwarfDebugInfo.DW_AT_type, buffer, pos);
1224-
pos = writeAttrForm(DwarfDebugInfo.DW_FORM_ref_addr, buffer, pos);
1224+
pos = writeAttrForm(DwarfDebugInfo.DW_FORM_ref4, buffer, pos);
12251225
/*
12261226
* Now terminate.
12271227
*/
@@ -1255,7 +1255,7 @@ private int writeInterfaceReferenceAbbrev(@SuppressWarnings("unused") DebugConte
12551255
pos = writeAttrType(DwarfDebugInfo.DW_AT_byte_size, buffer, pos);
12561256
pos = writeAttrForm(DwarfDebugInfo.DW_FORM_data1, buffer, pos);
12571257
pos = writeAttrType(DwarfDebugInfo.DW_AT_type, buffer, pos);
1258-
pos = writeAttrForm(DwarfDebugInfo.DW_FORM_ref_addr, buffer, pos);
1258+
pos = writeAttrForm(DwarfDebugInfo.DW_FORM_ref4, buffer, pos);
12591259
/*
12601260
* Now terminate.
12611261
*/
@@ -1293,6 +1293,9 @@ private int writeForeignReferenceAbbrev(@SuppressWarnings("unused") DebugContext
12931293
pos = writeFlag(DwarfDebugInfo.DW_CHILDREN_no, buffer, pos);
12941294
pos = writeAttrType(DwarfDebugInfo.DW_AT_byte_size, buffer, pos);
12951295
pos = writeAttrForm(DwarfDebugInfo.DW_FORM_data1, buffer, pos);
1296+
// n.b we use a (relocatable) ref_addr here rather than a (CU-relative) ref4
1297+
// because an unknown foreign pointer type will reference void which is not
1298+
// local to the current CU.
12961299
pos = writeAttrType(DwarfDebugInfo.DW_AT_type, buffer, pos);
12971300
pos = writeAttrForm(DwarfDebugInfo.DW_FORM_ref_addr, buffer, pos);
12981301
/*
@@ -1313,7 +1316,7 @@ private int writeForeignTypedefAbbrev(@SuppressWarnings("unused") DebugContext c
13131316
pos = writeAttrType(DwarfDebugInfo.DW_AT_name, buffer, pos);
13141317
pos = writeAttrForm(DwarfDebugInfo.DW_FORM_strp, buffer, pos);
13151318
pos = writeAttrType(DwarfDebugInfo.DW_AT_type, buffer, pos);
1316-
pos = writeAttrForm(DwarfDebugInfo.DW_FORM_ref_addr, buffer, pos);
1319+
pos = writeAttrForm(DwarfDebugInfo.DW_FORM_ref4, buffer, pos);
13171320
/*
13181321
* Now terminate.
13191322
*/
@@ -1381,6 +1384,9 @@ private int writeArrayDataTypeAbbrev(@SuppressWarnings("unused") DebugContext co
13811384
pos = writeAttrType(DwarfDebugInfo.DW_AT_byte_size, buffer, pos);
13821385
pos = writeAttrForm(DwarfDebugInfo.DW_FORM_data4, buffer, pos);
13831386
}
1387+
// n.b we use a (relocatable) ref_addr here rather than a (CU-relative) ref4
1388+
// because a foreign array type can reference another foreign type which is
1389+
// not in the current CU.
13841390
pos = writeAttrType(DwarfDebugInfo.DW_AT_type, buffer, pos);
13851391
pos = writeAttrForm(DwarfDebugInfo.DW_FORM_ref_addr, buffer, pos);
13861392
/*
@@ -1420,7 +1426,7 @@ private int writeMethodLocationAbbrev(@SuppressWarnings("unused") DebugContext c
14201426
pos = writeAttrType(DwarfDebugInfo.DW_AT_external, buffer, pos);
14211427
pos = writeAttrForm(DwarfDebugInfo.DW_FORM_flag, buffer, pos);
14221428
pos = writeAttrType(DwarfDebugInfo.DW_AT_specification, buffer, pos);
1423-
pos = writeAttrForm(DwarfDebugInfo.DW_FORM_ref_addr, buffer, pos);
1429+
pos = writeAttrForm(DwarfDebugInfo.DW_FORM_ref4, buffer, pos);
14241430
/*
14251431
* Now terminate.
14261432
*/
@@ -1509,7 +1515,7 @@ private int writeIndirectReferenceAbbrev(@SuppressWarnings("unused") DebugContex
15091515
pos = writeAttrType(DwarfDebugInfo.DW_AT_byte_size, buffer, pos);
15101516
pos = writeAttrForm(DwarfDebugInfo.DW_FORM_data1, buffer, pos);
15111517
pos = writeAttrType(DwarfDebugInfo.DW_AT_type, buffer, pos);
1512-
pos = writeAttrForm(DwarfDebugInfo.DW_FORM_ref_addr, buffer, pos);
1518+
pos = writeAttrForm(DwarfDebugInfo.DW_FORM_ref4, buffer, pos);
15131519
/*
15141520
* Now terminate.
15151521
*/

substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/elf/dwarf/DwarfInfoSectionImpl.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ private int writeBuiltInTypes(DebugContext context, byte[] buffer, int p) {
172172
// Write the single Java builtin unit header
173173
int lengthPos = pos;
174174
log(context, " [0x%08x] <0> Java Builtin Compile Unit", pos);
175+
cuStart = p;
175176
pos = writeCUHeader(buffer, pos);
176177
assert pos == lengthPos + DW_DIE_HEADER_SIZE;
177178
int abbrevCode = DwarfDebugInfo.DW_ABBREV_CODE_builtin_unit;
@@ -736,21 +737,19 @@ private int writeMethodDeclaration(DebugContext context, ClassEntry classEntry,
736737
pos = writeFlag((byte) 1, buffer, pos);
737738
int typeIdx = getLayoutIndex(classEntry);
738739
log(context, " [0x%08x] containing_type 0x%x (%s)", pos, typeIdx, classEntry.getTypeName());
739-
pos = writeInfoSectionOffset(typeIdx, buffer, pos);
740+
pos = writeAttrRef4(typeIdx, buffer, pos);
740741
if (abbrevCode == DwarfDebugInfo.DW_ABBREV_CODE_method_declaration) {
741742
/* Record the current position so we can back patch the object pointer. */
742743
int objectPointerIndex = pos;
743744
/*
744745
* Write a dummy ref address to move pos on to where the first parameter gets written.
745-
*
746-
* n.b. buffer is passed as null so we don't attempt to create a reloc!
747746
*/
748-
pos = writeInfoSectionOffset(0, null, pos);
747+
pos = writeAttrRef4(0, null, pos);
749748
/*
750749
* Now backpatch object pointer slot with current pos, identifying the first parameter.
751750
*/
752751
log(context, " [0x%08x] object_pointer 0x%x", objectPointerIndex, pos);
753-
writeInfoSectionOffset(pos, buffer, objectPointerIndex);
752+
writeAttrRef4(pos, buffer, objectPointerIndex);
754753
}
755754
/* Write method parameter declarations. */
756755
pos = writeMethodParameterDeclarations(context, method, fileIdx, 3, buffer, pos);
@@ -1116,7 +1115,7 @@ private int writeClassType(DebugContext context, ClassEntry classEntry, byte[] b
11161115
pos = writeAttrData1((byte) pointerSize, buffer, pos);
11171116
int layoutOffset = getLayoutIndex(classEntry);
11181117
log(context, " [0x%08x] type 0x%x", pos, layoutOffset);
1119-
pos = writeInfoSectionOffset(layoutOffset, buffer, pos);
1118+
pos = writeAttrRef4(layoutOffset, buffer, pos);
11201119

11211120
if (dwarfSections.useHeapBase()) {
11221121
/* Define an indirect pointer type referring to the indirect layout. */
@@ -1130,7 +1129,7 @@ private int writeClassType(DebugContext context, ClassEntry classEntry, byte[] b
11301129
pos = writeAttrData1((byte) oopReferenceSize, buffer, pos);
11311130
layoutOffset = getIndirectLayoutIndex(classEntry);
11321131
log(context, " [0x%08x] type 0x%x", pos, layoutOffset);
1133-
pos = writeInfoSectionOffset(layoutOffset, buffer, pos);
1132+
pos = writeAttrRef4(layoutOffset, buffer, pos);
11341133
} else {
11351134
setIndirectTypeIndex(classEntry, typeIdx);
11361135
}
@@ -1153,7 +1152,7 @@ private int writeInterfaceType(DebugContext context, InterfaceClassEntry interfa
11531152
pos = writeAttrData1((byte) pointerSize, buffer, pos);
11541153
int layoutOffset = getLayoutIndex(interfaceClassEntry);
11551154
log(context, " [0x%08x] type 0x%x", pos, layoutOffset);
1156-
pos = writeInfoSectionOffset(layoutOffset, buffer, pos);
1155+
pos = writeAttrRef4(layoutOffset, buffer, pos);
11571156

11581157
if (dwarfSections.useHeapBase()) {
11591158
/* Define an indirect pointer type referring to the indirect layout. */
@@ -1167,7 +1166,7 @@ private int writeInterfaceType(DebugContext context, InterfaceClassEntry interfa
11671166
pos = writeAttrData1((byte) byteSize, buffer, pos);
11681167
layoutOffset = getIndirectLayoutIndex(interfaceClassEntry);
11691168
log(context, " [0x%08x] type 0x%x", pos, layoutOffset);
1170-
pos = writeInfoSectionOffset(layoutOffset, buffer, pos);
1169+
pos = writeAttrRef4(layoutOffset, buffer, pos);
11711170
} else {
11721171
setIndirectTypeIndex(interfaceClassEntry, typeIdx);
11731172
}
@@ -1192,6 +1191,8 @@ private int writeForeignType(DebugContext context, ForeignTypeEntry foreignTypeE
11921191
int pointerSize = dwarfSections.pointerSize();
11931192
log(context, " [0x%08x] byte_size 0x%x", pos, pointerSize);
11941193
pos = writeAttrData1((byte) pointerSize, buffer, pos);
1194+
// Note that we write a ref_addr offset here because an unknown (void *)
1195+
// foreign type can have a layout offset that is not in its CU
11951196
log(context, " [0x%08x] type 0x%x", pos, layoutOffset);
11961197
pos = writeInfoSectionOffset(layoutOffset, buffer, pos);
11971198

@@ -1205,7 +1206,7 @@ private int writeForeignType(DebugContext context, ForeignTypeEntry foreignTypeE
12051206
log(context, " [0x%08x] name %s", pos, name);
12061207
pos = writeStrSectionOffset(name, buffer, pos);
12071208
log(context, " [0x%08x] type 0x%x", pos, refTypeIdx);
1208-
pos = writeInfoSectionOffset(refTypeIdx, buffer, pos);
1209+
pos = writeAttrRef4(refTypeIdx, buffer, pos);
12091210

12101211
setTypeIndex(foreignTypeEntry, typedefIdx);
12111212
// foreign pointers are never stored compressed so don't need a separate indirect type
@@ -1253,6 +1254,7 @@ private int writeArrays(DebugContext context, byte[] buffer, int p) {
12531254
log(context, " [0x%08x] array classes", p);
12541255
Cursor cursor = new Cursor(p);
12551256
arrayTypeStream().forEach(arrayTypeEntry -> {
1257+
cuStart = cursor.get();
12561258
cursor.set(writeArray(context, arrayTypeEntry, buffer, cursor.get()));
12571259
});
12581260
return cursor.get();
@@ -1484,7 +1486,7 @@ private int writeArrayTypes(DebugContext context, ArrayTypeEntry arrayTypeEntry,
14841486
log(context, " [0x%08x] byte_size 0x%x", pos, pointerSize);
14851487
pos = writeAttrData1((byte) pointerSize, buffer, pos);
14861488
log(context, " [0x%08x] type (pointer) 0x%x (%s)", pos, layoutOffset, name);
1487-
pos = writeInfoSectionOffset(layoutOffset, buffer, pos);
1489+
pos = writeAttrRef4(layoutOffset, buffer, pos);
14881490

14891491
if (dwarfSections.useHeapBase()) {
14901492
setIndirectTypeIndex(arrayTypeEntry, pos);
@@ -1497,7 +1499,7 @@ private int writeArrayTypes(DebugContext context, ArrayTypeEntry arrayTypeEntry,
14971499
log(context, " [0x%08x] byte_size 0x%x", pos, byteSize);
14981500
pos = writeAttrData1((byte) byteSize, buffer, pos);
14991501
log(context, " [0x%08x] type (pointer) 0x%x (%s)", pos, indirectLayoutOffset, name);
1500-
pos = writeInfoSectionOffset(indirectLayoutOffset, buffer, pos);
1502+
pos = writeAttrRef4(indirectLayoutOffset, buffer, pos);
15011503
} else {
15021504
setIndirectTypeIndex(arrayTypeEntry, typeIdx);
15031505
}
@@ -1532,7 +1534,7 @@ private int writeMethodLocation(DebugContext context, ClassEntry classEntry, Com
15321534
String methodKey = primary.getSymbolName();
15331535
int methodSpecOffset = getMethodDeclarationIndex(primary.getMethodEntry());
15341536
log(context, " [0x%08x] specification 0x%x (%s)", pos, methodSpecOffset, methodKey);
1535-
pos = writeInfoSectionOffset(methodSpecOffset, buffer, pos);
1537+
pos = writeAttrRef4(methodSpecOffset, buffer, pos);
15361538
HashMap<DebugLocalInfo, List<SubRange>> varRangeMap = primary.getVarRangeMap();
15371539
pos = writeMethodParameterLocations(context, varRangeMap, primary, 2, buffer, pos);
15381540
pos = writeMethodLocalLocations(context, varRangeMap, primary, 2, buffer, pos);

0 commit comments

Comments
 (0)