Skip to content

Commit 0bfd722

Browse files
zakkakstooke
andcommitted
Refactor: don't return RelocationRecord from markRelocationSite
Removes the need of creating a dummy RelocationRecord to work around the NPE observed in #3419 (comment) Co-Authored-By: Simon Tooke <[email protected]>
1 parent 92743b4 commit 0bfd722

File tree

9 files changed

+20
-30
lines changed

9 files changed

+20
-30
lines changed

substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/BasicProgbitsSectionImpl.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import com.oracle.objectfile.ObjectFile.ProgbitsSectionImpl;
3636
import com.oracle.objectfile.ObjectFile.RelocatableSectionImpl;
3737
import com.oracle.objectfile.ObjectFile.RelocationKind;
38-
import com.oracle.objectfile.ObjectFile.RelocationRecord;
3938
import com.oracle.objectfile.ObjectFile.Section;
4039

4140
/**
@@ -114,15 +113,15 @@ public List<Section> getElements() {
114113
}
115114

116115
@Override
117-
public RelocationRecord markRelocationSite(int offset, RelocationKind k, String symbolName, boolean useImplicitAddend, Long explicitAddend) {
118-
return ((RelocatableSectionImpl) getElement()).markRelocationSite(offset, ByteBuffer.wrap(getContent()).order(getOwner().getByteOrder()), k, symbolName, useImplicitAddend,
116+
public void markRelocationSite(int offset, RelocationKind k, String symbolName, boolean useImplicitAddend, Long explicitAddend) {
117+
((RelocatableSectionImpl) getElement()).markRelocationSite(offset, ByteBuffer.wrap(getContent()).order(getOwner().getByteOrder()), k, symbolName, useImplicitAddend,
119118
explicitAddend);
120119
}
121120

122121
@Override
123-
public final RelocationRecord markRelocationSite(int offset, ByteBuffer bb, RelocationKind k, String symbolName, boolean useImplicitAddend, Long explicitAddend) {
122+
public final void markRelocationSite(int offset, ByteBuffer bb, RelocationKind k, String symbolName, boolean useImplicitAddend, Long explicitAddend) {
124123
assert getContent() == null || bb.array() == getContent();
125-
return ((RelocatableSectionImpl) getElement()).markRelocationSite(offset, bb, k, symbolName, useImplicitAddend, explicitAddend);
124+
((RelocatableSectionImpl) getElement()).markRelocationSite(offset, bb, k, symbolName, useImplicitAddend, explicitAddend);
126125
}
127126

128127
@Override

substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/ObjectFile.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,9 +408,8 @@ public interface RelocatableSectionImpl extends ElementImpl {
408408
* bytes
409409
* @param useImplicitAddend whether the current bytes are to be used as an addend
410410
* @param explicitAddend a full-width addend, or null if useImplicitAddend is true
411-
* @return the relocation record created (or found, if it exists already)
412411
*/
413-
RelocationRecord markRelocationSite(int offset, ByteBuffer bb, RelocationKind k, String symbolName, boolean useImplicitAddend, Long explicitAddend);
412+
void markRelocationSite(int offset, ByteBuffer bb, RelocationKind k, String symbolName, boolean useImplicitAddend, Long explicitAddend);
414413

415414
/**
416415
* Force the creation of a relocation section/element for this section, and return it. This
@@ -441,7 +440,7 @@ public interface ProgbitsSectionImpl extends RelocatableSectionImpl {
441440
* passed a buffer. It uses the byte array accessed by {@link #getContent} and
442441
* {@link #setContent}.
443442
*/
444-
RelocationRecord markRelocationSite(int offset, RelocationKind k, String symbolName, boolean useImplicitAddend, Long explicitAddend);
443+
void markRelocationSite(int offset, RelocationKind k, String symbolName, boolean useImplicitAddend, Long explicitAddend);
445444
}
446445

447446
public interface NobitsSectionImpl extends ElementImpl {

substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/StringSectionImpl.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import com.oracle.objectfile.ObjectFile.Element;
3636
import com.oracle.objectfile.ObjectFile.ProgbitsSectionImpl;
3737
import com.oracle.objectfile.ObjectFile.RelocationKind;
38-
import com.oracle.objectfile.ObjectFile.RelocationRecord;
3938
import com.oracle.objectfile.io.AssemblyBuffer;
4039
import com.oracle.objectfile.io.OutputAssembler;
4140

@@ -125,12 +124,12 @@ public Element getOrCreateRelocationElement(boolean useImplicitAddend) {
125124
}
126125

127126
@Override
128-
public RelocationRecord markRelocationSite(int offset, RelocationKind k, String symbolName, boolean useImplicitAddend, Long explicitAddend) {
127+
public void markRelocationSite(int offset, RelocationKind k, String symbolName, boolean useImplicitAddend, Long explicitAddend) {
129128
throw new UnsupportedOperationException("can't mark relocaction sites in string section");
130129
}
131130

132131
@Override
133-
public RelocationRecord markRelocationSite(int offset, ByteBuffer bb, RelocationKind k, String symbolName, boolean useImplicitAddend, Long explicitAddend) {
132+
public void markRelocationSite(int offset, ByteBuffer bb, RelocationKind k, String symbolName, boolean useImplicitAddend, Long explicitAddend) {
134133
throw new UnsupportedOperationException("can't mark relocaction sites in string section");
135134
}
136135

substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/elf/ELFProgbitsSection.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public void setContent(byte[] c) {
6969
}
7070

7171
@Override
72-
public ObjectFile.RelocationRecord markRelocationSite(int offset, ObjectFile.RelocationKind k, String symbolName, boolean useImplicitAddend, Long explicitAddend) {
73-
return markRelocationSite(offset, ByteBuffer.wrap(getContent()).order(getOwner().getByteOrder()), k, symbolName, useImplicitAddend, explicitAddend);
72+
public void markRelocationSite(int offset, ObjectFile.RelocationKind k, String symbolName, boolean useImplicitAddend, Long explicitAddend) {
73+
markRelocationSite(offset, ByteBuffer.wrap(getContent()).order(getOwner().getByteOrder()), k, symbolName, useImplicitAddend, explicitAddend);
7474
}
7575
}

substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/elf/ELFUserDefinedSection.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import com.oracle.objectfile.LayoutDecisionMap;
3535
import com.oracle.objectfile.ObjectFile;
3636
import com.oracle.objectfile.ObjectFile.Element;
37-
import com.oracle.objectfile.ObjectFile.RelocationRecord;
3837
import com.oracle.objectfile.elf.ELFObjectFile.ELFSection;
3938
import com.oracle.objectfile.elf.ELFObjectFile.ELFSectionFlag;
4039
import com.oracle.objectfile.elf.ELFObjectFile.SectionType;
@@ -148,7 +147,7 @@ public Element getOrCreateRelocationElement(boolean useImplicitAddend) {
148147
}
149148

150149
@Override
151-
public RelocationRecord markRelocationSite(int offset, ByteBuffer bb, ObjectFile.RelocationKind k, String symbolName, boolean useImplicitAddend, Long explicitAddend) {
150+
public void markRelocationSite(int offset, ByteBuffer bb, ObjectFile.RelocationKind k, String symbolName, boolean useImplicitAddend, Long explicitAddend) {
152151
if (useImplicitAddend != (explicitAddend == null)) {
153152
throw new IllegalArgumentException("must have either an explicit or implicit addend");
154153
}
@@ -157,6 +156,6 @@ public RelocationRecord markRelocationSite(int offset, ByteBuffer bb, ObjectFile
157156
assert symbolName != null;
158157
ELFSymtab.Entry ent = syms.getSymbol(symbolName);
159158
assert ent != null;
160-
return rs.addEntry(this, offset, ELFMachine.getRelocation(getOwner().getMachine(), k), ent, explicitAddend);
159+
rs.addEntry(this, offset, ELFMachine.getRelocation(getOwner().getMachine(), k), ent, explicitAddend);
161160
}
162161
}

substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/macho/MachORegularSection.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import com.oracle.objectfile.ObjectFile;
3131
import com.oracle.objectfile.ObjectFile.ProgbitsSectionImpl;
3232
import com.oracle.objectfile.ObjectFile.RelocationKind;
33-
import com.oracle.objectfile.ObjectFile.RelocationRecord;
3433
import com.oracle.objectfile.macho.MachOObjectFile.SectionFlag;
3534
import com.oracle.objectfile.macho.MachOObjectFile.Segment64Command;
3635

@@ -51,8 +50,8 @@ public byte[] getContent() {
5150
}
5251

5352
@Override
54-
public RelocationRecord markRelocationSite(int offset, RelocationKind k, String symbolName, boolean useImplicitAddend, Long explicitAddend) {
55-
return markRelocationSite(offset, ByteBuffer.wrap(getContent()).order(getOwner().getByteOrder()), k, symbolName, useImplicitAddend, explicitAddend);
53+
public void markRelocationSite(int offset, RelocationKind k, String symbolName, boolean useImplicitAddend, Long explicitAddend) {
54+
markRelocationSite(offset, ByteBuffer.wrap(getContent()).order(getOwner().getByteOrder()), k, symbolName, useImplicitAddend, explicitAddend);
5655
}
5756

5857
}

substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/macho/MachOUserDefinedSection.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import com.oracle.objectfile.ObjectFile;
3737
import com.oracle.objectfile.ObjectFile.Element;
3838
import com.oracle.objectfile.ObjectFile.RelocationKind;
39-
import com.oracle.objectfile.ObjectFile.RelocationRecord;
4039
import com.oracle.objectfile.ObjectFile.Segment;
4140
import com.oracle.objectfile.ObjectFile.Symbol;
4241
import com.oracle.objectfile.io.AssemblyBuffer;
@@ -160,7 +159,7 @@ public MachORelocationElement getOrCreateRelocationElement(boolean useImplicitAd
160159
}
161160

162161
@Override
163-
public RelocationRecord markRelocationSite(int offset, ByteBuffer bb, RelocationKind k, String symbolName, boolean useImplicitAddend, Long explicitAddend) {
162+
public void markRelocationSite(int offset, ByteBuffer bb, RelocationKind k, String symbolName, boolean useImplicitAddend, Long explicitAddend) {
164163
MachORelocationElement el = getOrCreateRelocationElement(useImplicitAddend);
165164
AssemblyBuffer sbb = new AssemblyBuffer(bb);
166165
sbb.setByteOrder(getOwner().getByteOrder());
@@ -215,7 +214,5 @@ public RelocationRecord markRelocationSite(int offset, ByteBuffer bb, Relocation
215214
sbb.pop();
216215
RelocationInfo rec = new RelocationInfo(el, this, offset, length, k, symbolName, createAsLocalReloc);
217216
el.add(rec);
218-
219-
return rec;
220217
}
221218
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public void setContent(byte[] c) {
6969
}
7070

7171
@Override
72-
public ObjectFile.RelocationRecord markRelocationSite(int offset, ObjectFile.RelocationKind k, String symbolName, boolean useImplicitAddend, Long explicitAddend) {
73-
return markRelocationSite(offset, ByteBuffer.wrap(getContent()).order(getOwner().getByteOrder()), k, symbolName, useImplicitAddend, explicitAddend);
72+
public void markRelocationSite(int offset, ObjectFile.RelocationKind k, String symbolName, boolean useImplicitAddend, Long explicitAddend) {
73+
markRelocationSite(offset, ByteBuffer.wrap(getContent()).order(getOwner().getByteOrder()), k, symbolName, useImplicitAddend, explicitAddend);
7474
}
7575
}

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import com.oracle.objectfile.LayoutDecisionMap;
3535
import com.oracle.objectfile.ObjectFile;
3636
import com.oracle.objectfile.ObjectFile.Element;
37-
import com.oracle.objectfile.ObjectFile.RelocationRecord;
3837
import com.oracle.objectfile.io.AssemblyBuffer;
3938
import com.oracle.objectfile.pecoff.PECoffObjectFile.PECoffSection;
4039
import com.oracle.objectfile.pecoff.PECoffObjectFile.PECoffSectionFlag;
@@ -141,7 +140,7 @@ public Element getOrCreateRelocationElement(boolean useImplicitAddend) {
141140
}
142141

143142
@Override
144-
public RelocationRecord markRelocationSite(int offset, ByteBuffer bb, ObjectFile.RelocationKind k, String symbolName, boolean useImplicitAddend, Long explicitAddend) {
143+
public void markRelocationSite(int offset, ByteBuffer bb, ObjectFile.RelocationKind k, String symbolName, boolean useImplicitAddend, Long explicitAddend) {
145144
if (useImplicitAddend != (explicitAddend == null)) {
146145
throw new IllegalArgumentException("must have either an explicit or implicit addend");
147146
}
@@ -151,8 +150,7 @@ public RelocationRecord markRelocationSite(int offset, ByteBuffer bb, ObjectFile
151150
PECoffSymtab.Entry ent = syms.getSymbol(symbolName);
152151
if (ent == null) {
153152
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);
153+
return;
156154
}
157155

158156
AssemblyBuffer sbb = new AssemblyBuffer(bb);
@@ -198,7 +196,7 @@ public RelocationRecord markRelocationSite(int offset, ByteBuffer bb, ObjectFile
198196
// return ByteBuffer cursor to where it was
199197
sbb.pop();
200198

201-
return rs.addEntry(this, offset, PECoffMachine.getRelocation(getOwner().getMachine(), k), ent, explicitAddend);
199+
rs.addEntry(this, offset, PECoffMachine.getRelocation(getOwner().getMachine(), k), ent, explicitAddend);
202200
}
203201

204202
/**

0 commit comments

Comments
 (0)