oracle / graal

GraalVM compiles Java applications into native executables that start instantly, scale fast, and use fewer compute resources 🚀
https://www.graalvm.org
Other
19.99k stars 1.6k forks source link

[LLVM] OpenSSL-1.1.1 cannot be loaded into GraalVM-21.3.0, works with 21.2.0 #4059

Open cagriuslu-adyen opened 2 years ago

cagriuslu-adyen commented 2 years ago

Describe GraalVM and your environment :

- GraalVM version: 21.3.0
- EE
- JDK11
- centos 7
- amd64
- java -Xinternalversion: Java HotSpot(TM) 64-Bit Server VM (11.0.13+10-LTS-jvmci-21.3-b05) for linux-amd64 JRE (11.0.13+10-LTS-jvmci-21.3-b05), built on Oct 16 2021 17:12:34 by "buildslave" with gcc 7.3.0

Have you verified this issue still happens when using the latest snapshot? No, the issue happens on the latest release version BUT NOT on 21.2.0.

Describe the issue OpenSSL-1.1.1 shared library built using the bundled LLVM toolchain throws org.graalvm.polyglot.PolyglotException: java.lang.AssertionError: Invalid ElementType of Vector: VariableBitWidthType during Context.eval(source).

How to compile the LLVM bitcode that causes the problem I use the bundled LLVM toolchain. This is how my CMake configures the OpenSSL library

env MAKEFLAGS="-j4" env TARGETMACH=x86_64-unknown-linux-musl CC=/home/vagrant/graalvm-ee-java11-21.3.0/languages/llvm/managed/bin/clang RANLIB=/home/vagrant/graalvm-ee-java11-21.3.0/languages/llvm/managed/bin/ranlib LD=/home/vagrant/graalvm-ee-java11-21.3.0/languages/llvm/managed/bin/ld AS=/home/vagrant/graalvm-ee-java11-21.3.0/languages/llvm/managed/bin/as AR=/home/vagrant/graalvm-ee-java11-21.3.0/languages/llvm/managed/bin/ar ./Configure --sysroot=/home/vagrant/graalvm-ee-java11-21.3.0/languages/llvm/managed/bin/../ linux-x86_64-clang -DOPENSSL_NO_HEARTBEATS --libdir=lib no-asm no-whirlpool no-camellia no-idea no-mdc2 shared no-rc5 no-ssl2 no-ssl3 no-unit-test --prefix=/home/vagrant/build-broken --openssldir=/home/vagrant/build-broken/lib/openssl -fPIC -DOPENSSL_NO_SECURE_MEMORY
env MAKEFLAGS="-j4" make depend

And then this is how cmake builds it:

env MAKEFLAGS="-j4" env TARGETMACH=x86_64-unknown-linux-musl CC=/home/vagrant/graalvm-ee-java11-21.3.0/languages/llvm/managed/bin/clang RANLIB=/home/vagrant/graalvm-ee-java11-21.3.0/languages/llvm/managed/bin/ranlib LD=/home/vagrant/graalvm-ee-java11-21.3.0/languages/llvm/managed/bin/ld AS=/home/vagrant/graalvm-ee-java11-21.3.0/languages/llvm/managed/bin/as AR=/home/vagrant/graalvm-ee-java11-21.3.0/languages/llvm/managed/bin/ar make

Code snippet or code repository that reproduces the problem Here is the Java file in which I try to load the ssl library into GraalVM.

import java.io.*;
import org.graalvm.polyglot.*;

class Remote {
  public static void main(String[] args) throws Exception {
    Context polyglot = Context.newBuilder().allowAllAccess(true).option("llvm.managed", "true").build();
    File file = new File("libssl.so");
    Source source = Source.newBuilder("llvm", file).build();
    Value cpart = polyglot.eval(source); // << exception location
  }
}

I actually don't use openssl by itself, other parts of our code uses it internally. Any library that links ssl (dynamic or static) has the same exception.

Everything works with GraalVM 21.2.0, it is only broken in 21.3.0.

Additional info If I compile openssl using the bundled LLVM in 21.2.0, it works on 21.3.0. The bundled LLVM in 21.3.0 might be the culprit.

munishchouhan commented 2 years ago

@cagriuslu-adyen thanks for reporting the issue, we will check it out and get back to you

lukasstadler commented 2 years ago

Thanks for the thorough report. We've moved to a newer llvm version in 21.3. The new version produces different bitcode for some uncommon integer bit sizes, so that it hits a bug in Sulong. We're looking into it.

lukasstadler commented 2 years ago

tracked internally as GR-35906