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

Linkage Checker to verify method references to JRE classes #1607

Merged
merged 10 commits into from
Aug 26, 2020

Conversation

suztomo
Copy link
Contributor

@suztomo suztomo commented Aug 19, 2020

Fixes #1605 .

@google-cla google-cla bot added the cla: yes label Aug 19, 2020
Comment on lines +44 to +99
<LinkageError>
<Target>
<Class name="java.lang.invoke.MethodHandle" />
</Target>
<Source>
<Package name="com.oracle.svm" />
</Source>
<Reason>
GraalVM-related libraries depend on Java Compiler Interface (JVMCI) that
only exists in special JDK. These missing classes are false positives, because
the code is only invoked when running in a GraalVM.
https://github.com/GoogleCloudPlatform/cloud-opensource-java/issues/929
</Reason>
</LinkageError>
<LinkageError>
<Target>
<Class name="java.lang.invoke.MethodHandle" />
</Target>
<Source>
<Package name="com.oracle.graal" />
</Source>
<Reason>
GraalVM-related libraries depend on Java Compiler Interface (JVMCI) that
only exists in special JDK. These missing classes are false positives, because
the code is only invoked when running in a GraalVM.
https://github.com/GoogleCloudPlatform/cloud-opensource-java/issues/929
</Reason>
</LinkageError>
<LinkageError>
<Target>
<Class name="java.lang.invoke.MethodHandle" />
</Target>
<Source>
<Package name="org.graalvm" />
</Source>
<Reason>
GraalVM-related libraries depend on Java Compiler Interface (JVMCI) that
only exists in special JDK. These missing classes are false positives, because
the code is only invoked when running in a GraalVM.
https://github.com/GoogleCloudPlatform/cloud-opensource-java/issues/929
</Reason>
</LinkageError>
<LinkageError>
<Target>
<Class name="java.lang.invoke.MethodHandle" />
</Target>
<Source>
<Package name="com.oracle.truffle" />
</Source>
<Reason>
GraalVM-related libraries depend on Java Compiler Interface (JVMCI) that
only exists in special JDK. These missing classes are false positives, because
the code is only invoked when running in a GraalVM.
https://github.com/GoogleCloudPlatform/cloud-opensource-java/issues/929
</Reason>
</LinkageError>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because now we check JDK classes, GraalVM-related exclusion is needed.

@Test
public void testFindLinkageProblems_referenceToNonexistentMethodForJava8() throws IOException {
// Protobuf-java 3.12.4 contained wrong byte code to reference non-existent method in JRE 1.8
// https://github.com/protocolbuffers/protobuf/issues/7827
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is Kristen's finding yesterday.

@@ -239,8 +239,14 @@ private boolean problemFilter(LinkageProblem linkageProblem) {
String targetClassName = symbol.getClassBinaryName();
String methodName = symbol.getName();

// Skip references to Java runtime class. For example, java.lang.String.
if (classDumper.isSystemClass(targetClassName)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was hiding the protobuf's linkage error against Java 8 runtime protocolbuffers/protobuf#7827

@suztomo suztomo requested a review from elharo August 19, 2020 04:07
return Optional.empty();
}
// Skip references from Java runtime class. For example, java.lang.String.
// It is possible for wrongly configured Java compiler to generate bad byte code that references
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure lines 246-248 explain this code. It explains what we're not doing, not what we are. I suggest deleting them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed this if-statement and moved the explanation to array class skipping.


@Test
public void testFindLinkageProblems_referenceToNonexistentMethodForJava8() throws IOException {
// Protobuf-java 3.12.4 contained wrong byte code to reference non-existent method in JRE 1.8
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

protobuf-java 3.12.4 references a Java 11 method that does not exist in Java 8

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

Copy link
Contributor

@elharo elharo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a really interesting one. Some take-aways:

  1. The compiler doesn't catch all linkage errors, even to classes in the JDK.
  2. We should report errors that the project (here Kristen) can't fix so they can understand them and report the errors to the team that can fix them.

Copy link
Contributor Author

@suztomo suztomo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@elharo PTAL.


@Test
public void testFindLinkageProblems_referenceToNonexistentMethodForJava8() throws IOException {
// Protobuf-java 3.12.4 contained wrong byte code to reference non-existent method in JRE 1.8
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

return Optional.empty();
}
// Skip references from Java runtime class. For example, java.lang.String.
// It is possible for wrongly configured Java compiler to generate bad byte code that references
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed this if-statement and moved the explanation to array class skipping.

Copy link
Contributor

@elharo elharo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs merge with master

@@ -126,8 +126,7 @@ JavaClass loadJavaClass(String className) throws ClassNotFoundException {
/** Returns true if {@code className} is available in the system class loader. */
boolean isSystemClass(String className) {
try {
if (className.startsWith("[")) {
// Array class
if (isArrayClass(className)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will we catch a reference to an array of a missing class?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but not from array class reference. When there's a reference to array of a class, there should be a reference to the class in the same class file.

// Skip references to Java runtime class. For example, java.lang.String.
if (classDumper.isSystemClass(targetClassName)) {
if (ClassDumper.isArrayClass(targetClassName)) {
// Skip references to array class. However, we want to check other JDK-provided classes,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete this comment. It describes what the code is not doing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

Copy link
Contributor Author

@suztomo suztomo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@elharo PTAL.

@@ -126,8 +126,7 @@ JavaClass loadJavaClass(String className) throws ClassNotFoundException {
/** Returns true if {@code className} is available in the system class loader. */
boolean isSystemClass(String className) {
try {
if (className.startsWith("[")) {
// Array class
if (isArrayClass(className)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but not from array class reference. When there's a reference to array of a class, there should be a reference to the class in the same class file.

// Skip references to Java runtime class. For example, java.lang.String.
if (classDumper.isSystemClass(targetClassName)) {
if (ClassDumper.isArrayClass(targetClassName)) {
// Skip references to array class. However, we want to check other JDK-provided classes,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

Copy link
Contributor

@elharo elharo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merge to master please

@suztomo suztomo merged commit 354bfee into master Aug 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can Linkage Checker detect the bad Java8-incompatible byte code
2 participants