oracle / graal

GraalVM compiles Java applications into native executables that start instantly, scale fast, and use fewer compute resources šŸš€
https://www.graalvm.org
Other
20.4k stars 1.64k forks source link

Failure to link missing symbol _Java_sun_misc_Perf_createByteArray #2160

Closed headius closed 4 years ago

headius commented 4 years ago

The build gets to linking but fails with another missing symbol, similar to #1995.

Describe GraalVM and your environment :

Fatal error: java.lang.RuntimeException: java.lang.RuntimeException: There was an error linking the native image: Linker command exited with 1

Linker command executed:
cc -v -o /Users/headius/projects/jruby/org.jruby.main.nativemain -Wl,-no_compact_unwind -Wl,-exported_symbols_list -Wl,/var/folders/cq/ylcgmnn556x33f5hsqd0h54h0000gn/T/SVM-7815651263568320567/exported_symbols.list -Wl,-x -arch x86_64 -L/var/folders/cq/ylcgmnn556x33f5hsqd0h54h0000gn/T/SVM-7815651263568320567 -L/Library/Java/JavaVirtualMachines/graalvm-ce-java8-20.0.0/Contents/Home/jre/lib -L/Library/Java/JavaVirtualMachines/graalvm-ce-java8-20.0.0/Contents/Home/jre/lib/svm/clibraries/darwin-amd64 /var/folders/cq/ylcgmnn556x33f5hsqd0h54h0000gn/T/SVM-7815651263568320567/org.jruby.main.nativemain.o /Library/Java/JavaVirtualMachines/graalvm-ce-java8-20.0.0/Contents/Home/jre/lib/libnet.a /Library/Java/JavaVirtualMachines/graalvm-ce-java8-20.0.0/Contents/Home/jre/lib/libzip.a /Library/Java/JavaVirtualMachines/graalvm-ce-java8-20.0.0/Contents/Home/jre/lib/libjava.a /Library/Java/JavaVirtualMachines/graalvm-ce-java8-20.0.0/Contents/Home/jre/lib/libnio.a /Library/Java/JavaVirtualMachines/graalvm-ce-java8-20.0.0/Contents/Home/jre/lib/libjaas.a /Library/Java/JavaVirtualMachines/graalvm-ce-java8-20.0.0/Contents/Home/jre/lib/svm/clibraries/darwin-amd64/libffi.a /Library/Java/JavaVirtualMachines/graalvm-ce-java8-20.0.0/Contents/Home/jre/lib/svm/clibraries/darwin-amd64/liblibchelper.a /Library/Java/JavaVirtualMachines/graalvm-ce-java8-20.0.0/Contents/Home/jre/lib/svm/clibraries/darwin-amd64/libjvm.a /Library/Java/JavaVirtualMachines/graalvm-ce-java8-20.0.0/Contents/Home/jre/lib/svm/clibraries/darwin-amd64/libstrictmath.a -lpthread -Wl,-framework,CoreFoundation -ldl -lz

Linker command ouput:
Apple clang version 11.0.0 (clang-1100.0.33.12)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -lto_library /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libLTO.dylib -dynamic -arch x86_64 -macosx_version_min 10.14.0 -o /Users/headius/projects/jruby/org.jruby.main.nativemain -L/var/folders/cq/ylcgmnn556x33f5hsqd0h54h0000gn/T/SVM-7815651263568320567 -L/Library/Java/JavaVirtualMachines/graalvm-ce-java8-20.0.0/Contents/Home/jre/lib -L/Library/Java/JavaVirtualMachines/graalvm-ce-java8-20.0.0/Contents/Home/jre/lib/svm/clibraries/darwin-amd64 -no_compact_unwind -exported_symbols_list /var/folders/cq/ylcgmnn556x33f5hsqd0h54h0000gn/T/SVM-7815651263568320567/exported_symbols.list -x /var/folders/cq/ylcgmnn556x33f5hsqd0h54h0000gn/T/SVM-7815651263568320567/org.jruby.main.nativemain.o /Library/Java/JavaVirtualMachines/graalvm-ce-java8-20.0.0/Contents/Home/jre/lib/libnet.a /Library/Java/JavaVirtualMachines/graalvm-ce-java8-20.0.0/Contents/Home/jre/lib/libzip.a /Library/Java/JavaVirtualMachines/graalvm-ce-java8-20.0.0/Contents/Home/jre/lib/libjava.a /Library/Java/JavaVirtualMachines/graalvm-ce-java8-20.0.0/Contents/Home/jre/lib/libnio.a /Library/Java/JavaVirtualMachines/graalvm-ce-java8-20.0.0/Contents/Home/jre/lib/libjaas.a /Library/Java/JavaVirtualMachines/graalvm-ce-java8-20.0.0/Contents/Home/jre/lib/svm/clibraries/darwin-amd64/libffi.a /Library/Java/JavaVirtualMachines/graalvm-ce-java8-20.0.0/Contents/Home/jre/lib/svm/clibraries/darwin-amd64/liblibchelper.a /Library/Java/JavaVirtualMachines/graalvm-ce-java8-20.0.0/Contents/Home/jre/lib/svm/clibraries/darwin-amd64/libjvm.a /Library/Java/JavaVirtualMachines/graalvm-ce-java8-20.0.0/Contents/Home/jre/lib/svm/clibraries/darwin-amd64/libstrictmath.a -lpthread -framework CoreFoundation -ldl -lz -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.0/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
  "_Java_sun_misc_Perf_createByteArray", referenced from:
      ___svm_version_info in org.jruby.main.nativemain.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at java.util.concurrent.ForkJoinTask.getThrowableException(ForkJoinTask.java:593)
    at java.util.concurrent.ForkJoinTask.get(ForkJoinTask.java:1005)
    at com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:462)
    at com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:357)
    at com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:501)
    at com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:115)
Caused by: java.lang.RuntimeException: There was an error linking the native image: Linker command exited with 1

Linker command executed:
cc -v -o /Users/headius/projects/jruby/org.jruby.main.nativemain -Wl,-no_compact_unwind -Wl,-exported_symbols_list -Wl,/var/folders/cq/ylcgmnn556x33f5hsqd0h54h0000gn/T/SVM-7815651263568320567/exported_symbols.list -Wl,-x -arch x86_64 -L/var/folders/cq/ylcgmnn556x33f5hsqd0h54h0000gn/T/SVM-7815651263568320567 -L/Library/Java/JavaVirtualMachines/graalvm-ce-java8-20.0.0/Contents/Home/jre/lib -L/Library/Java/JavaVirtualMachines/graalvm-ce-java8-20.0.0/Contents/Home/jre/lib/svm/clibraries/darwin-amd64 /var/folders/cq/ylcgmnn556x33f5hsqd0h54h0000gn/T/SVM-7815651263568320567/org.jruby.main.nativemain.o /Library/Java/JavaVirtualMachines/graalvm-ce-java8-20.0.0/Contents/Home/jre/lib/libnet.a /Library/Java/JavaVirtualMachines/graalvm-ce-java8-20.0.0/Contents/Home/jre/lib/libzip.a /Library/Java/JavaVirtualMachines/graalvm-ce-java8-20.0.0/Contents/Home/jre/lib/libjava.a /Library/Java/JavaVirtualMachines/graalvm-ce-java8-20.0.0/Contents/Home/jre/lib/libnio.a /Library/Java/JavaVirtualMachines/graalvm-ce-java8-20.0.0/Contents/Home/jre/lib/libjaas.a /Library/Java/JavaVirtualMachines/graalvm-ce-java8-20.0.0/Contents/Home/jre/lib/svm/clibraries/darwin-amd64/libffi.a /Library/Java/JavaVirtualMachines/graalvm-ce-java8-20.0.0/Contents/Home/jre/lib/svm/clibraries/darwin-amd64/liblibchelper.a /Library/Java/JavaVirtualMachines/graalvm-ce-java8-20.0.0/Contents/Home/jre/lib/svm/clibraries/darwin-amd64/libjvm.a /Library/Java/JavaVirtualMachines/graalvm-ce-java8-20.0.0/Contents/Home/jre/lib/svm/clibraries/darwin-amd64/libstrictmath.a -lpthread -Wl,-framework,CoreFoundation -ldl -lz

Linker command ouput:
Apple clang version 11.0.0 (clang-1100.0.33.12)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -lto_library /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libLTO.dylib -dynamic -arch x86_64 -macosx_version_min 10.14.0 -o /Users/headius/projects/jruby/org.jruby.main.nativemain -L/var/folders/cq/ylcgmnn556x33f5hsqd0h54h0000gn/T/SVM-7815651263568320567 -L/Library/Java/JavaVirtualMachines/graalvm-ce-java8-20.0.0/Contents/Home/jre/lib -L/Library/Java/JavaVirtualMachines/graalvm-ce-java8-20.0.0/Contents/Home/jre/lib/svm/clibraries/darwin-amd64 -no_compact_unwind -exported_symbols_list /var/folders/cq/ylcgmnn556x33f5hsqd0h54h0000gn/T/SVM-7815651263568320567/exported_symbols.list -x /var/folders/cq/ylcgmnn556x33f5hsqd0h54h0000gn/T/SVM-7815651263568320567/org.jruby.main.nativemain.o /Library/Java/JavaVirtualMachines/graalvm-ce-java8-20.0.0/Contents/Home/jre/lib/libnet.a /Library/Java/JavaVirtualMachines/graalvm-ce-java8-20.0.0/Contents/Home/jre/lib/libzip.a /Library/Java/JavaVirtualMachines/graalvm-ce-java8-20.0.0/Contents/Home/jre/lib/libjava.a /Library/Java/JavaVirtualMachines/graalvm-ce-java8-20.0.0/Contents/Home/jre/lib/libnio.a /Library/Java/JavaVirtualMachines/graalvm-ce-java8-20.0.0/Contents/Home/jre/lib/libjaas.a /Library/Java/JavaVirtualMachines/graalvm-ce-java8-20.0.0/Contents/Home/jre/lib/svm/clibraries/darwin-amd64/libffi.a /Library/Java/JavaVirtualMachines/graalvm-ce-java8-20.0.0/Contents/Home/jre/lib/svm/clibraries/darwin-amd64/liblibchelper.a /Library/Java/JavaVirtualMachines/graalvm-ce-java8-20.0.0/Contents/Home/jre/lib/svm/clibraries/darwin-amd64/libjvm.a /Library/Java/JavaVirtualMachines/graalvm-ce-java8-20.0.0/Contents/Home/jre/lib/svm/clibraries/darwin-amd64/libstrictmath.a -lpthread -framework CoreFoundation -ldl -lz -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.0/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
  "_Java_sun_misc_Perf_createByteArray", referenced from:
      ___svm_version_info in org.jruby.main.nativemain.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

    at com.oracle.svm.hosted.image.NativeBootImageViaCC.handleLinkerFailure(NativeBootImageViaCC.java:424)
    at com.oracle.svm.hosted.image.NativeBootImageViaCC.write(NativeBootImageViaCC.java:399)
    at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:657)
    at com.oracle.svm.hosted.NativeImageGenerator.lambda$run$0(NativeImageGenerator.java:445)
    at java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1386)
    at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
    at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
    at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
    at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Error: Image build request failed with exit status 1
com.oracle.svm.driver.NativeImage$NativeImageError: Image build request failed with exit status 1
    at com.oracle.svm.driver.NativeImage.showError(NativeImage.java:1527)
    at com.oracle.svm.driver.NativeImage.build(NativeImage.java:1289)
    at com.oracle.svm.driver.NativeImage.performBuild(NativeImage.java:1250)
    at com.oracle.svm.driver.NativeImage.main(NativeImage.java:1209)

The build is based on a modified JRuby, using the following command line:

native-image --no-server -Djruby.debug.parser=true -Djruby.reify.variables=false \
             -Djruby.home=`pwd` -Djruby.native.enabled=false -Djruby.graavm.native.compile --no-fallback \
             --report-unsupported-elements-at-runtime \
             --initialize-at-build-time=com.headius.backport9.stack.StackWalker,com.headius.backport9.stack.impl.StackWalker8,com.headius.invokebinder.Signature,org.jruby.NativeImageClassInitializer,org.jcodings.specific.EUCJPEncoding,org.jcodings.specific.SJISEncoding,org.jcodings.specific.UTF8Encoding,org.jcodings.specific.ASCIIEncoding,org.jcodings.specific.USASCIIEncoding,org.jcodings.specific.ISO8859_1Encoding,org.jcodings.specific.EmacsMuleEncoding,org.jcodings.specific.UTF16BEEncoding,org.jcodings.util,org.jruby.util.log.StandardErrorLogger,org.jcodings.ascii.AsciiTables,org.jruby,org.jruby.runtime.EventHook,org.jruby.util.cli.Options,com.headius.options,org.jruby.RubyInstanceConfig,org.jruby.util.SafePropertyAccessor,org.jcodings.specific.UTF32LEEncoding,org.jcodings.specific.UTF32BEEncoding,org.jcodings.specific.UTF16LEEncoding,org.joda.time,org.joda.time.format,org.joni,org.jcodings.EncodingDB,org.joni.Analyser,org.jcodings.IntHolder,org.joni.Parser,jnr.constants.platform.OpenFlags,jnr.constants.platform.ConstantResolver,jnr.posix.util.Platform,org.joni.Lexer,org.joni.ScannerSupport,org.jcodings.transcode.EConvResult,org.jcodings.ObjPtr,jnr.constants,org.jcodings,org.jruby.gen,org.jruby,org.jcodings.unicode,org.jcodings.transcode.specific,jnr.posix.JavaPOSIX,jnr.posix.JavaLibCHelper,org.jruby.util.NormalizedFile,jnr.posix.POSIXFactory,jnr.posix.JavaSecuredFile,jnr.posix.JavaLibCHelper,com.headius.backport9.buffer.Buffers,jnr.posix,jnr.ffi.Platform,jnr.ffi.Platform\$SingletonHolder,jnr.ffi.Platform\$Darwin,jnr.ffi.Platform\$1,org.joda.time.tz.data.America.Chicago,org.jruby.gen.org\$jruby\$RubyBasicObject\$POPULATOR,com.headius.backport9.modules.impl.ModuleDummy,org.jruby.main.NativeMain -H:+TraceClassInitialization -H:ReflectionConfigurationFiles=native-config/reflect-config.json -H:ResourceConfigurationFiles=native-config/resource-config.json \
             --allow-incomplete-classpath --verbose -cp lib/jruby.jar \
             org.jruby.main.NativeMain
headius commented 4 years ago

Tested on Linux with the same result.

eginez commented 4 years ago

Hi @headius is there a way to reproduce this issue? usually a code snippet or a repository is helpful for that

headius commented 4 years ago

I will try to come up with something. Building JRuby for native-image currently requires breaking changes I can't commit to any of our branches, so it may be a bit before I return to that work.

Is there anything I can look at to figure out why we're hitting this internal Perf class? I know we're not referencing it directly.

eginez commented 4 years ago

You can use the -H:+PrintAnalysisCallTree to try to detect what is bringing in that method

christianwimmer commented 4 years ago

The Perf class is not supported, and all code from it should be unreachable. To diagnose the issue better, https://github.com/oracle/graal/commit/39ec03d4e7a4d69015d72dc8a4c96fda75261299 marks the method as deleted so that a reachability stack trace is printed.