Skip to content

Commit 369ea76

Browse files
committed
svm: add --enable-native-access hosted/api option
No need to allow native access to the application modules in the driver. They will not be loaded on the boot module layer, so specifying them there has no effect anyways.
1 parent ee6037c commit 369ea76

File tree

4 files changed

+7
-30
lines changed

4 files changed

+7
-30
lines changed

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/NativeImageClassLoaderOptions.java

+5
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ public class NativeImageClassLoaderOptions {
4848
" <target-module> can be ALL-UNNAMED to read all unnamed modules.")//
4949
public static final HostedOptionKey<AccumulatingLocatableMultiOptionValue.Strings> AddReads = new HostedOptionKey<>(AccumulatingLocatableMultiOptionValue.Strings.build());
5050

51+
@APIOption(name = "enable-native-access", launcherOption = true, valueSeparator = {APIOption.WHITESPACE_SEPARATOR, '='})//
52+
@Option(help = "A comma-separated list of modules that are permitted to perform restricted native operations." +
53+
" The module name can also be ALL-UNNAMED.")//
54+
public static final HostedOptionKey<AccumulatingLocatableMultiOptionValue.Strings> EnableNativeAccess = new HostedOptionKey<>(AccumulatingLocatableMultiOptionValue.Strings.build());
55+
5156
@APIOption(name = "list-modules")//
5257
@Option(help = "List observable modules and exit.")//
5358
public static final HostedOptionKey<Boolean> ListModules = new HostedOptionKey<>(false);

substratevm/src/com.oracle.svm.driver/resources/Help.txt

-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ where options include:
3131
-J<flag> pass <flag> directly to the JVM running the image generator
3232
--diagnostics-mode enable diagnostics output: class initialization, substitutions, etc.
3333
--enable-preview allow classes to depend on preview features of this release
34-
--enable-native-access <module name>[,<module name>...]
35-
modules that are permitted to perform restricted native operations.
36-
<module name> can also be ALL-UNNAMED.
3734
--verbose enable verbose output
3835
--version print product version and exit
3936
--help print this help message

substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/DefaultOptionHandler.java

-20
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ class DefaultOptionHandler extends NativeImage.OptionHandler<NativeImage> {
4747
/* Defunct legacy options that we have to accept to maintain backward compatibility */
4848
private static final String noServerOption = "--no-server";
4949

50-
private static final String nativeAccessOption = "--enable-native-access";
51-
5250
DefaultOptionHandler(NativeImage nativeImage) {
5351
super(nativeImage);
5452
}
@@ -130,15 +128,6 @@ public boolean consume(ArgumentQueue args) {
130128
args.poll();
131129
nativeImage.addCustomJavaArgs("--enable-preview");
132130
return true;
133-
case nativeAccessOption:
134-
args.poll();
135-
String modules = args.poll();
136-
if (modules == null) {
137-
NativeImage.showError(nativeAccessOption + moduleSetModifierOptionErrorMessage);
138-
}
139-
nativeImage.addEnableNativeAccess(modules);
140-
nativeImage.addEnableNativeAccess("org.graalvm.nativeimage.foreign");
141-
return true;
142131
}
143132

144133
String singleArgClasspathPrefix = newStyleClasspathOptionName + "=";
@@ -212,15 +201,6 @@ public boolean consume(ArgumentQueue args) {
212201
nativeImage.addLimitedModules(limitModulesArgs);
213202
return true;
214203
}
215-
if (headArg.startsWith(nativeAccessOption + "=")) {
216-
args.poll();
217-
String nativeAccessModules = headArg.substring(nativeAccessOption.length() + 1);
218-
if (nativeAccessModules.isEmpty()) {
219-
NativeImage.showError(headArg + moduleSetModifierOptionErrorMessage);
220-
}
221-
nativeImage.addCustomJavaArgs(headArg + ",org.graalvm.nativeimage.foreign");
222-
return true;
223-
}
224204
return false;
225205
}
226206

substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java

+2-7
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,6 @@ private static <T> String oR(OptionKey<T> option) {
302302
private final List<ExcludeConfig> excludedConfigs = new ArrayList<>();
303303
private final LinkedHashSet<String> addModules = new LinkedHashSet<>();
304304
private final LinkedHashSet<String> limitModules = new LinkedHashSet<>();
305-
private final LinkedHashSet<String> enableNativeAccessModules = new LinkedHashSet<>();
306305

307306
private long imageBuilderPid = -1;
308307

@@ -1384,8 +1383,8 @@ private int completeImageBuild() {
13841383
if (config.modulePathBuild && !finalImageClasspath.isEmpty()) {
13851384
imageBuilderJavaArgs.add(DefaultOptionHandler.addModulesOption + "=ALL-DEFAULT");
13861385
}
1387-
enableNativeAccessModules.addAll(getModulesFromPath(imageBuilderModulePath).keySet());
1388-
assert !enableNativeAccessModules.isEmpty();
1386+
// allow native access for all modules on the image builder module path
1387+
var enableNativeAccessModules = getModulesFromPath(imageBuilderModulePath).keySet();
13891388
imageBuilderJavaArgs.add("--enable-native-access=" + String.join(",", enableNativeAccessModules));
13901389

13911390
boolean useColorfulOutput = configureBuildOutput();
@@ -2016,10 +2015,6 @@ public void addLimitedModules(String limitModulesArg) {
20162015
limitModules.addAll(Arrays.asList(SubstrateUtil.split(limitModulesArg, ",")));
20172016
}
20182017

2019-
public void addEnableNativeAccess(String enableNativeAccessArg) {
2020-
enableNativeAccessModules.addAll(Arrays.asList(SubstrateUtil.split(enableNativeAccessArg, ",")));
2021-
}
2022-
20232018
void addImageBuilderClasspath(Path classpath) {
20242019
imageBuilderClasspath.add(canonicalize(classpath));
20252020
}

0 commit comments

Comments
 (0)