Skip to content

Commit

Permalink
svm: add --enable-native-access hosted/api option
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
zapster committed Nov 12, 2024
1 parent ee6037c commit 369ea76
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ public class NativeImageClassLoaderOptions {
" <target-module> can be ALL-UNNAMED to read all unnamed modules.")//
public static final HostedOptionKey<AccumulatingLocatableMultiOptionValue.Strings> AddReads = new HostedOptionKey<>(AccumulatingLocatableMultiOptionValue.Strings.build());

@APIOption(name = "enable-native-access", launcherOption = true, valueSeparator = {APIOption.WHITESPACE_SEPARATOR, '='})//
@Option(help = "A comma-separated list of modules that are permitted to perform restricted native operations." +
" The module name can also be ALL-UNNAMED.")//
public static final HostedOptionKey<AccumulatingLocatableMultiOptionValue.Strings> EnableNativeAccess = new HostedOptionKey<>(AccumulatingLocatableMultiOptionValue.Strings.build());

@APIOption(name = "list-modules")//
@Option(help = "List observable modules and exit.")//
public static final HostedOptionKey<Boolean> ListModules = new HostedOptionKey<>(false);
Expand Down
3 changes: 0 additions & 3 deletions substratevm/src/com.oracle.svm.driver/resources/Help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ where options include:
-J<flag> pass <flag> directly to the JVM running the image generator
--diagnostics-mode enable diagnostics output: class initialization, substitutions, etc.
--enable-preview allow classes to depend on preview features of this release
--enable-native-access <module name>[,<module name>...]
modules that are permitted to perform restricted native operations.
<module name> can also be ALL-UNNAMED.
--verbose enable verbose output
--version print product version and exit
--help print this help message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ class DefaultOptionHandler extends NativeImage.OptionHandler<NativeImage> {
/* Defunct legacy options that we have to accept to maintain backward compatibility */
private static final String noServerOption = "--no-server";

private static final String nativeAccessOption = "--enable-native-access";

DefaultOptionHandler(NativeImage nativeImage) {
super(nativeImage);
}
Expand Down Expand Up @@ -130,15 +128,6 @@ public boolean consume(ArgumentQueue args) {
args.poll();
nativeImage.addCustomJavaArgs("--enable-preview");
return true;
case nativeAccessOption:
args.poll();
String modules = args.poll();
if (modules == null) {
NativeImage.showError(nativeAccessOption + moduleSetModifierOptionErrorMessage);
}
nativeImage.addEnableNativeAccess(modules);
nativeImage.addEnableNativeAccess("org.graalvm.nativeimage.foreign");
return true;
}

String singleArgClasspathPrefix = newStyleClasspathOptionName + "=";
Expand Down Expand Up @@ -212,15 +201,6 @@ public boolean consume(ArgumentQueue args) {
nativeImage.addLimitedModules(limitModulesArgs);
return true;
}
if (headArg.startsWith(nativeAccessOption + "=")) {
args.poll();
String nativeAccessModules = headArg.substring(nativeAccessOption.length() + 1);
if (nativeAccessModules.isEmpty()) {
NativeImage.showError(headArg + moduleSetModifierOptionErrorMessage);
}
nativeImage.addCustomJavaArgs(headArg + ",org.graalvm.nativeimage.foreign");
return true;
}
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,6 @@ private static <T> String oR(OptionKey<T> option) {
private final List<ExcludeConfig> excludedConfigs = new ArrayList<>();
private final LinkedHashSet<String> addModules = new LinkedHashSet<>();
private final LinkedHashSet<String> limitModules = new LinkedHashSet<>();
private final LinkedHashSet<String> enableNativeAccessModules = new LinkedHashSet<>();

private long imageBuilderPid = -1;

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

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

public void addEnableNativeAccess(String enableNativeAccessArg) {
enableNativeAccessModules.addAll(Arrays.asList(SubstrateUtil.split(enableNativeAccessArg, ",")));
}

void addImageBuilderClasspath(Path classpath) {
imageBuilderClasspath.add(canonicalize(classpath));
}
Expand Down

0 comments on commit 369ea76

Please sign in to comment.