Skip to content

Commit 92743b4

Browse files
zakkakstooke
andcommitted
Return dummy relocation entry for non-existing symbols
This allows us to work around the NPE observed in #3419 (comment) Co-Authored-By: Simon Tooke <[email protected]>
1 parent f5450b3 commit 92743b4

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/pecoff/PECoffRelocationTable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ interface PECoffRelocationMethod extends RelocationMethod {
5858
long toLong();
5959
}
6060

61-
private static final class Entry implements RelocationRecord {
61+
static final class Entry implements RelocationRecord {
6262
final PECoffSection section;
6363
final long offset;
6464
final PECoffRelocationMethod t;

substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/pecoff/PECoffUserDefinedSection.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,11 @@ public RelocationRecord markRelocationSite(int offset, ByteBuffer bb, ObjectFile
149149
PECoffRelocationTable rs = (PECoffRelocationTable) getOrCreateRelocationElement(useImplicitAddend);
150150
assert symbolName != null;
151151
PECoffSymtab.Entry ent = syms.getSymbol(symbolName);
152-
assert ent != null;
152+
if (ent == null) {
153+
warn("attempting to mark relocation site for non-existent symbol " + symbolName);
154+
/* Return (but do not add to entry list) dummy relocation entry. It is never used (in GraalVM CE) */
155+
return new PECoffRelocationTable.Entry(this, offset, PECoffMachine.getRelocation(getOwner().getMachine(), k), null, 0L);
156+
}
153157

154158
AssemblyBuffer sbb = new AssemblyBuffer(bb);
155159
sbb.setByteOrder(getOwner().getByteOrder());
@@ -196,4 +200,13 @@ public RelocationRecord markRelocationSite(int offset, ByteBuffer bb, ObjectFile
196200

197201
return rs.addEntry(this, offset, PECoffMachine.getRelocation(getOwner().getMachine(), k), ent, explicitAddend);
198202
}
203+
204+
/**
205+
* Report a warning message in SVM.
206+
*
207+
* @param msg warning message that is printed.
208+
*/
209+
private static void warn(String msg) {
210+
System.err.println("Warning: " + msg);
211+
}
199212
}

0 commit comments

Comments
 (0)