-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgraal.patch
185 lines (173 loc) · 10.4 KB
/
graal.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
diff --git a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/thread/PosixJavaThreads.java b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/thread/PosixJavaThreads.java
index 3bfc5210c..1d401f463 100644
--- a/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/thread/PosixJavaThreads.java
+++ b/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/thread/PosixJavaThreads.java
@@ -109,9 +109,14 @@ public final class PosixJavaThreads extends JavaThreads {
prepareStartData(thread, startData);
Pthread.pthread_tPointer newThread = StackValue.get(Pthread.pthread_tPointer.class);
- PosixUtils.checkStatusIs0(
- Pthread.pthread_create(newThread, attributes, PosixJavaThreads.pthreadStartRoutine.getFunctionPointer(), startData),
- "PosixJavaThreads.start0: pthread_create");
+ int status = Pthread.pthread_create(newThread, attributes, PosixJavaThreads.pthreadStartRoutine.getFunctionPointer(), startData);
+ if (status == 11) {
+ throw new Error("The enclave ran out of TCS slots when calling from a new thread into the enclave. " +
+ "Please either increase the 'maxThreads' value in your enclave configuration or use fewer " +
+ "threads inside the enclave.");
+ } else {
+ PosixUtils.checkStatusIs0(status, "PosixJavaThreads.start0: pthread_create");
+ }
setPthreadIdentifier(thread, newThread.read());
Pthread.pthread_attr_destroy(attributes);
}
diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java
index 37a4551..b155ed4 100644
--- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java
+++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java
@@ -420,6 +420,18 @@ public class SubstrateOptions {
@Option(help = "Provide java.lang.Terminator exit handlers for executable images", type = User)//
public static final HostedOptionKey<Boolean> InstallExitHandlers = new HostedOptionKey<>(false);
+ @Option(help = "Use static linking", type = OptionType.Expert)
+ public static final HostedOptionKey<Boolean> UseStaticLinking = new HostedOptionKey<>(false);
+
+ @Option(help = "Export symbols in linked static libraries", type = OptionType.Expert)
+ public static final HostedOptionKey<Boolean> ExportStaticSymbols = new HostedOptionKey<>(false);
+
+ @Option(help = "Default libraries to be excluded by the linker (list of comma-separated library names, i.e., dl,pthreads)", type = OptionType.Expert)
+ public static final HostedOptionKey<LocatableMultiOptionValue.Strings> ExcludeLibraries = new HostedOptionKey<>(new LocatableMultiOptionValue.Strings());
+
+ @Option(help = "Exclude loading net library", type = OptionType.Expert)
+ public static final HostedOptionKey<Boolean> ExcludeLoadingNetwork = new HostedOptionKey<>(false);
+
@Option(help = "When set to true, the image generator verifies that the image heap does not contain a home directory as a substring", type = User)//
public static final HostedOptionKey<Boolean> DetectUserDirectoriesInImageHeap = new HostedOptionKey<>(false);
diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/c/NativeLibraries.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/c/NativeLibraries.java
index d9b2596..e11730c 100644
--- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/c/NativeLibraries.java
+++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/c/NativeLibraries.java
@@ -608,10 +608,12 @@ public final class NativeLibraries {
return false;
}
for (CLibrary lib : annotated) {
- if (lib.requireStatic()) {
- addStaticNonJniLibrary(lib.value(), lib.dependsOn());
- } else {
- addDynamicNonJniLibrary(lib.value());
+ if (!OptionUtils.flatten(",", SubstrateOptions.ExcludeLibraries.getValue()).contains(lib.value())) {
+ if (lib.requireStatic()) {
+ addStaticNonJniLibrary(lib.value(), lib.dependsOn());
+ } else {
+ addDynamicNonJniLibrary(lib.value());
+ }
}
}
annotated.clear();
diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImageViaCC.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImageViaCC.java
index 92e7346..d838ff7 100644
--- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImageViaCC.java
+++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImageViaCC.java
@@ -125,8 +125,10 @@ public abstract class NativeImageViaCC extends NativeImage {
additionalPreOptions.add("-Wl,--dynamic-list");
additionalPreOptions.add("-Wl," + exportedSymbolsPath.toAbsolutePath());
- // Drop global symbols in linked static libraries: not covered by --dynamic-list
- additionalPreOptions.add("-Wl,--exclude-libs,ALL");
+ if (!SubstrateOptions.ExportStaticSymbols.getValue()) {
+ // Drop global symbols in linked static libraries: not covered by --dynamic-list
+ additionalPreOptions.add("-Wl,--exclude-libs,ALL");
+ }
} catch (IOException e) {
VMError.shouldNotReachHere();
}
@@ -155,7 +157,9 @@ public abstract class NativeImageViaCC extends NativeImage {
}
break;
case SHARED_LIBRARY:
- cmd.add("-shared");
+ if (!SubstrateOptions.UseStaticLinking.getValue()) {
+ cmd.add("-shared");
+ }
break;
default:
VMError.shouldNotReachHere();
diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/sources/SourceCache.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/sources/SourceCache.java
index 8fcbce1..305b9ec 100644
--- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/sources/SourceCache.java
+++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/sources/SourceCache.java
@@ -313,7 +313,7 @@ public class SourceCache {
moduleName = ModuleSupport.getModuleName(clazz);
}
- if (moduleName != null) {
+ if (moduleName != null && !specialSrcRoots.isEmpty()) {
for (String specialRootModule : specialRootModules) {
if (moduleName.equals(specialRootModule)) {
for (Path srcRoot : specialSrcRoots.get(specialRootModule)) {
diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationAwt.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationAwt.java
index dd43417..0ae578e 100644
--- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationAwt.java
+++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationAwt.java
@@ -42,7 +42,7 @@ import org.graalvm.nativeimage.impl.InternalPlatform;
import java.awt.GraphicsEnvironment;
@Platforms({InternalPlatform.PLATFORM_JNI.class})
-@AutomaticFeature
+//@AutomaticFeature
@SuppressWarnings({"unused"})
public class JNIRegistrationAwt extends JNIRegistrationUtil implements Feature {
diff --git a/substratevm/src/com.oracle.svm.jni/src/com/oracle/svm/jni/JNILibraryInitializer.java b/substratevm/src/com.oracle.svm.jni/src/com/oracle/svm/jni/JNILibraryInitializer.java
index 2e01394..7630aed 100644
--- a/substratevm/src/com.oracle.svm.jni/src/com/oracle/svm/jni/JNILibraryInitializer.java
+++ b/substratevm/src/com.oracle.svm.jni/src/com/oracle/svm/jni/JNILibraryInitializer.java
@@ -51,2 +51,3 @@ import com.oracle.svm.core.jdk.NativeLibrarySupport;
import com.oracle.svm.jni.functions.JNIFunctionTables;
import com.oracle.svm.jni.nativeapi.JNIJavaVM;
+import com.oracle.svm.core.SubstrateOptions;
@@ -113,6 +113,10 @@ public class JNILibraryInitializer implements NativeLibrarySupport.LibraryInitia
@Override
public void initialize(PlatformNativeLibrarySupport.NativeLibrary lib) {
+ if (SubstrateOptions.ExcludeLoadingNetwork.hasBeenSet() && SubstrateOptions.ExcludeLoadingNetwork.getValue()) {
+ return;
+ }
+
String libName = lib.getCanonicalIdentifier();
PointerBase onLoadFunction;
if (lib.isBuiltin()) {
diff --git a/substratevm/src/com.oracle.svm.native.libchelper/src/cpuid.c b/substratevm/src/com.oracle.svm.native.libchelper/src/cpuid.c
index 5656dec..1e39f62 100644
--- a/substratevm/src/com.oracle.svm.native.libchelper/src/cpuid.c
+++ b/substratevm/src/com.oracle.svm.native.libchelper/src/cpuid.c
@@ -110,6 +110,15 @@ int get_cpuid (unsigned int leaf, unsigned int *eax, unsigned int *ebx, unsigned
#define bit_SHA_compat 0x20000000
#define bit_FMA_compat 0x00001000
+/*
+ * CPUID is not available inside an SGX enclave.
+ * If a clean method that we could use to determine whether or not we were inside
+ * an enclave, we could use this to steer feature detection.
+ */
+int cpuid_available() {
+ return 0;
+}
+
/*
* Extracts the CPU features by using cpuid.h.
* Note: This function is implemented in C as cpuid.h
@@ -528,6 +537,24 @@ static void set_cpufeatures(CPUFeatures *features, CpuidInfo *_cpuid_info)
void determineCPUFeatures(CPUFeatures *features)
{
+ // Return a minimal hard coded set of features
+ // TODO: Find a way to safely perform proper feature detection. Alternatively, find a way to
+ // determine if we are in an enclave and steer feature detection appropriately.
+ if (!cpuid_available()) {
+
+ // Required by graalvm (will not work without)
+ features->fSSE = 1;
+ features->fSSE2 = 1;
+
+ // Additional features supported by all processors that also support the above (may as well include them!)
+ features->fCX8 = 1;
+ features->fCMOV = 1;
+ features->fFXSR = 1;
+ features->fMMX = 1;
+ features->fTSC = 1;
+
+ return;
+ }
CpuidInfo cpuid_info_data = {0};
CpuidInfo *_cpuid_info = &cpuid_info_data;