Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply patch from SDK #1

Merged
merged 1 commit into from
Jul 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,20 @@ public static boolean useLLVMBackend() {
@Option(help = "Provide java.lang.Terminator exit handlers", type = User)//
public static final HostedOptionKey<Boolean> InstallExitHandlers = new HostedOptionKey<>(false);

// CONCLAVE start
@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);
// CONCLAVE end

@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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -612,10 +612,14 @@ public boolean processAnnotated() {
return false;
}
for (CLibrary lib : annotated) {
if (lib.requireStatic()) {
addStaticNonJniLibrary(lib.value(), lib.dependsOn());
} else {
addDynamicNonJniLibrary(lib.value());
// CONCLAVE start
if (!OptionUtils.flatten(",", SubstrateOptions.ExcludeLibraries.getValue()).contains(lib.value())) {
if (lib.requireStatic()) {
addStaticNonJniLibrary(lib.value(), lib.dependsOn());
} else {
addDynamicNonJniLibrary(lib.value());
}
// CONCLAVE end
}
}
annotated.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,12 @@ class BinutilsCCLinkerInvocation extends CCLinkerInvocation {
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");
// CONCLAVE start
if (!SubstrateOptions.ExportStaticSymbols.getValue()) {
// Drop global symbols in linked static libraries: not covered by --dynamic-list
additionalPreOptions.add("-Wl,--exclude-libs,ALL");
}
// CONCLAVE end
} catch (IOException e) {
VMError.shouldNotReachHere();
}
Expand Down Expand Up @@ -143,7 +147,11 @@ protected void setOutputKind(List<String> cmd) {
}
break;
case SHARED_LIBRARY:
cmd.add("-shared");
// CONCLAVE start
if (!SubstrateOptions.UseStaticLinking.getValue()) {
cmd.add("-shared");
}
// CONCLAVE end
break;
default:
VMError.shouldNotReachHere();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,9 @@ protected Path tryCacheFile(Path filePath, Class<?> clazz) {
moduleName = ModuleSupport.getModuleName(clazz);
}

if (moduleName != null) {
// CONCLAVE start
if (moduleName != null && !specialSrcRoots.isEmpty()) {
// CONCLAVE end
for (String specialRootModule : specialRootModules) {
if (moduleName.equals(specialRootModule)) {
for (Path srcRoot : specialSrcRoots.get(specialRootModule)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@
import java.util.Optional;

@Platforms({InternalPlatform.PLATFORM_JNI.class})
@AutomaticFeature
// CONCLAVE start
//@AutomaticFeature
// CONCLAVE end
@SuppressWarnings({"unused"})
public class JNIRegistrationAwt extends JNIRegistrationUtil implements Feature {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import com.oracle.svm.core.util.ImageHeapMap;
import com.oracle.svm.jni.functions.JNIFunctionTables;
import com.oracle.svm.jni.nativeapi.JNIJavaVM;
import com.oracle.svm.core.SubstrateOptions;

interface JNIOnLoadFunctionPointer extends CFunctionPointer {
@InvokeCFunctionPointer
Expand Down Expand Up @@ -113,6 +114,12 @@ public boolean isBuiltinLibrary(String libName) {

@Override
public void initialize(PlatformNativeLibrarySupport.NativeLibrary lib) {
// CONCLAVE start
if (SubstrateOptions.ExcludeLoadingNetwork.hasBeenSet() && SubstrateOptions.ExcludeLoadingNetwork.getValue()) {
return;
}
// CONCLAVE end

String libName = lib.getCanonicalIdentifier();
PointerBase onLoadFunction;
if (lib.isBuiltin()) {
Expand Down
31 changes: 31 additions & 0 deletions substratevm/src/com.oracle.svm.native.libchelper/src/cpuid.c
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,17 @@ static void set_cpufeatures(CPUFeatures *features, CpuidInfo *_cpuid_info)
}
}

// CONCLAVE start
/*
* 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;
}
// CONCLAVE end

/*
* Extracts the CPU features by using cpuid.h.
* Note: This function is implemented in C as cpuid.h
Expand All @@ -528,6 +539,26 @@ static void set_cpufeatures(CPUFeatures *features, CpuidInfo *_cpuid_info)
void determineCPUFeatures(CPUFeatures *features)
{

// CONCLAVE start
// 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;
}
// CONCLAVE end

CpuidInfo cpuid_info_data = {0};
CpuidInfo *_cpuid_info = &cpuid_info_data;
Expand Down