25
25
26
26
package com .oracle .svm .interpreter ;
27
27
28
+ import static com .oracle .svm .interpreter .metadata .InterpreterResolvedJavaMethod .EST_NO_ENTRY ;
29
+
28
30
import java .util .Collection ;
29
31
32
+ import org .graalvm .nativeimage .Platform ;
33
+ import org .graalvm .nativeimage .Platforms ;
34
+
30
35
import com .oracle .objectfile .ObjectFile ;
36
+ import com .oracle .svm .core .SubstrateControlFlowIntegrity ;
31
37
import com .oracle .svm .core .config .ConfigurationValues ;
32
38
import com .oracle .svm .core .graal .amd64 .AMD64InterpreterStubs ;
33
39
import com .oracle .svm .core .graal .amd64 .SubstrateAMD64RegisterConfig ;
34
- import com .oracle .svm .core .graal .meta .KnownOffsets ;
35
40
import com .oracle .svm .core .graal .meta .SubstrateRegisterConfig ;
36
41
import com .oracle .svm .core .util .VMError ;
37
- import com .oracle .svm .interpreter .metadata .InterpreterResolvedJavaMethod ;
38
42
import com .oracle .svm .hosted .image .NativeImage ;
43
+ import com .oracle .svm .interpreter .metadata .InterpreterResolvedJavaMethod ;
39
44
40
45
import jdk .graal .compiler .asm .Assembler ;
41
46
import jdk .graal .compiler .asm .Label ;
42
47
import jdk .graal .compiler .asm .amd64 .AMD64BaseAssembler ;
43
48
import jdk .graal .compiler .asm .amd64 .AMD64MacroAssembler ;
44
49
import jdk .graal .compiler .core .common .LIRKind ;
50
+ import jdk .graal .compiler .core .common .NumUtil ;
45
51
import jdk .vm .ci .meta .ResolvedJavaMethod ;
46
52
47
- import static com .oracle .svm .interpreter .metadata .InterpreterResolvedJavaMethod .EST_NO_ENTRY ;
48
-
49
53
public class AMD64InterpreterStubSection extends InterpreterStubSection {
50
54
public AMD64InterpreterStubSection () {
51
55
this .target = ConfigurationValues .getTarget ();
@@ -57,6 +61,10 @@ public AMD64InterpreterStubSection() {
57
61
protected byte [] generateEnterStubs (Collection <InterpreterResolvedJavaMethod > methods ) {
58
62
AMD64MacroAssembler masm = new AMD64MacroAssembler (target );
59
63
64
+ if (SubstrateControlFlowIntegrity .enabled ()) {
65
+ VMError .unimplemented ("GR-63035: Add CFI support for interpreter stubs" );
66
+ }
67
+
60
68
Label interpEnterStub = new Label ();
61
69
masm .bind (interpEnterStub );
62
70
@@ -80,35 +88,39 @@ protected byte[] generateEnterStubs(Collection<InterpreterResolvedJavaMethod> me
80
88
81
89
@ Override
82
90
public int getVTableStubSize () {
83
- return 16 ;
91
+ int branchTargetAlignment = ConfigurationValues .getTarget ().wordSize * 2 ;
92
+ int stubSize = 10 ;
93
+
94
+ return NumUtil .roundUp (stubSize , branchTargetAlignment );
84
95
}
85
96
86
97
@ Override
87
- protected byte [] generateVtableEnterStubs (int maxVtableIndex ) {
98
+ protected byte [] generateVTableEnterStubs (int maxVTableIndex ) {
88
99
AMD64MacroAssembler masm = new AMD64MacroAssembler (target );
89
100
101
+ if (SubstrateControlFlowIntegrity .enabled ()) {
102
+ VMError .unimplemented ("GR-63035: Add CFI support for interpreter stubs" );
103
+ }
104
+
90
105
Label interpEnterStub = new Label ();
91
106
masm .bind (interpEnterStub );
92
107
93
108
masm .setCodePatchingAnnotationConsumer (this ::recordEnterStubForPatching );
94
109
masm .jmp ();
95
110
96
111
masm .align (getVTableStubSize ());
112
+ recordVTableStubBaseOffset (masm .position ());
97
113
98
- int vTableEntrySize = KnownOffsets .singleton ().getVTableEntrySize ();
99
- for (int index = 0 ; index < maxVtableIndex ; index ++) {
100
- int stubStart = masm .position ();
101
- int stubEnd = stubStart + getVTableStubSize ();
102
-
103
- int offset = index * vTableEntrySize ;
114
+ for (int vTableIndex = 0 ; vTableIndex < maxVTableIndex ; vTableIndex ++) {
115
+ int expectedStubEnd = masm .position () + getVTableStubSize ();
104
116
105
- /* pass current vtable offset as hidden argument */
106
- masm .movq (AMD64InterpreterStubs .TRAMPOLINE_ARGUMENT , offset );
117
+ /* pass current vTable index as hidden argument */
118
+ masm .moveInt (AMD64InterpreterStubs .TRAMPOLINE_ARGUMENT , vTableIndex );
107
119
108
120
masm .jmp (interpEnterStub );
109
121
110
122
masm .align (getVTableStubSize ());
111
- assert masm .position () == stubEnd ;
123
+ assert masm .position () == expectedStubEnd ;
112
124
}
113
125
114
126
return masm .close (true );
@@ -130,6 +142,7 @@ private void recordEnterStubForPatching(Assembler.CodeAnnotation a) {
130
142
resolverPatchRelocationKind = ObjectFile .RelocationKind .getPCRelative (annotation .operandSize );
131
143
}
132
144
145
+ @ Platforms (Platform .HOSTED_ONLY .class )
133
146
@ Override
134
147
protected void markEnterStubPatch (ObjectFile .ProgbitsSectionImpl pltBuffer , ResolvedJavaMethod enterStub ) {
135
148
pltBuffer .markRelocationSite (resolverPatchOffset , resolverPatchRelocationKind , NativeImage .localSymbolNameForMethod (enterStub ), resolverKindAddend );
0 commit comments