-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[GR-33359] Fix image name argument parsing when combined with -m option #3622
Conversation
@ivan-ristovic unfortunately these changes break def native_image_func(args, **kwargs):
all_args = base_args + common_args + args
path = query_native_image(all_args, r'^-H:Path(@[^=]*)?=')
name = query_native_image(all_args, r'^-H:Name(@[^=]*)?=') <<< THIS
image = join(path, name)
_native_image(all_args, **kwargs)
return image in built_image = native_image([
'--verbose', '-H:Path=' + build_dir,
'--trace-class-initialization=hello.lib.Greeter', # also test native-image-diagnostics-agent
] + moduletest_run_args) in There is no |
The reason is that now if (hasMainClassModule) {
imageBuilderArgs.add(oH(SubstrateOptions.Name, "image-name from module-name") + mainClassModule.toLowerCase());
} is not used anymore. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comments
@olpaw Yes, I realise now that in fact we wish to do the same as before, just skip overruling - I moved the check, I think it should be fine now. |
Rerunning in internal CI now ... |
PR is in merge queue |
Summary
This PR adresses two problems related to
native-image
argument handling. Namely, it:NullPointerException
in cases when a class could not be found on the provided module path--module
argument, the image name is not mistakenly interpreted as a class nameDetails
Main class resolving
Currently, our main class resolving is done via:
graal/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGeneratorRunner.java
Line 340 in 8d70605
There is a catch block present for
ClassNotFoundException
, however, looking at the call chain, it is possible that control will reachjava.lang.Class.forName(Module, String)
, and by looking at the documentation for this method the return value could benull
- which is currently not covered. Therefore, the following line will produce aNullPointerException
:graal/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGeneratorRunner.java
Line 351 in 8d70605
Image name handling in the presence of
--module
optionInvoking
native-image
with the following argumentswill produce a binary with the name
foo
. However, combining this with the--module
(-m
for short) option, for examplewill cause a
NullPointerException
in the same line as mentioned above. This is tied to class resolving which could returnnull
, however it is a misinterpreted main class argument when-m
option is present - the image name will be interpreted as an overrule for the class name.Implementation details
This PR solves this problem by reusing the same overrule exclusion code used when
-jar
option is present:graal/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java
Line 1168 in 8d70605
As for main class resolving, a check is added to ensure that the
mainClass
field is notnull
before proceeding onto entry method lookup.