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

Possible bug in CCCompilerInvoke causes "Unable to detect supported LINUX native software development toolchain" #3168

Closed
cloudpaul opened this issue Jan 29, 2021 · 3 comments

Comments

@cloudpaul
Copy link

cloudpaul commented Jan 29, 2021

Describe the issue
Attempting to build https://github.com/graalvm/graalvm-demos/tree/master/native-image-workshop results in error "Unable to detect supported LINUX native software development toolchain."

Steps to reproduce the issue
Please include both build steps as well as run steps

  1. git clone https://github.com/graalvm/graalvm-demos.git
  2. cd native-image-workshop
  3. mvn clean package exec:exec -PNATIVE_IMAGE

Investigation
Adding --debug-attach to the <buildArgs> Maven element allows me to attach a debugger, and stepping into com.oracle.svm.hosted.c.codegen.CCCompilerInvoke reveals the following:

at line 367 we join the output from, in my case, gcc -v

result = createCompilerInfo(compilerPath, new Scanner(String.join(System.lineSeparator(), lines)));

this should result in "clang version " matching at line 224:

if (scanner.findInLine("clang version ") != null) {

however it does not match and the method returns null resulting in the thrown exception.
This appears to be because String.join(System.lineSeparator(), lines) breaks the pattern matching.
This can be demonstated by changing the value passed to StringReader in the constructor of Scanner so that it does not contain line separators i.e. it is a single line. If we do this then the pattern matching works.

Describe GraalVM and your environment:

  • GraalVM version CE 21.0.0
  • JDK major version: 11
  • OS: MX-19.3_x64 patito feo February 15 2020 base: Debian GNU/Linux 10 (buster)
    Kernel : Linux 4.19.0-6-amd64 (x86_64)
    Version : Feature/instrumentation api #1 SMP Debian 4.19.67-2+deb10u2 (2019-11-11)
    C Library : GNU C Library / (Debian GLIBC 2.28-10) 2.28
    Distribution : Debian GNU/Linux 10 (buster)
  • Architecture: AMD64

More details
Consider adding the --native-image-info and --verbose flags when building your native image and paste output below.

Add any other information about the problem here. Especially important are stack traces or log output. Feel free to link to gists or to screenshots if necessary.

[INFO] Executing: /home/paul/.sdkman/candidates/java/21.0.0.r11-grl/bin/native-image -cp /home/paul/.m2/repository/log4j/log4j/1.2.17/log4j-1.2.17.jar:/media/paul/7BC262EF03F9976C/dev/graalvm/graalvm-demos/native-image-workshop/target/graalvmnidemos-1.0-SNAPSHOT.jar --no-fallback --no-server -H:Class=oracle.App -H:Name=file-count
[file-count:18405]    classlist:   1,507.64 ms,  0.96 GB
[file-count:18405]        setup:     568.39 ms,  0.96 GB
Error: Unable to detect supported LINUX native software development toolchain.
Error: To prevent native-toolchain checking provide command-line option -H:-CheckToolchain
com.oracle.svm.core.util.UserError$UserException: Unable to detect supported LINUX native software development toolchain.
To prevent native-toolchain checking provide command-line option -H:-CheckToolchain
	at com.oracle.svm.core.util.UserError.abort(UserError.java:139)
	at com.oracle.svm.hosted.c.codegen.CCompilerInvoker.addSkipCheckingInfo(CCompilerInvoker.java:104)
	at com.oracle.svm.hosted.c.codegen.CCompilerInvoker.<init>(CCompilerInvoker.java:72)
	at com.oracle.svm.hosted.c.codegen.CCompilerInvoker$LinuxCCompilerInvoker.<init>(CCompilerInvoker.java:205)
	at com.oracle.svm.hosted.c.codegen.CCompilerInvoker.create(CCompilerInvoker.java:80)
	at com.oracle.svm.hosted.NativeImageGenerator.setupNativeImage(NativeImageGenerator.java:877)
	at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:561)
	at com.oracle.svm.hosted.NativeImageGenerator.lambda$run$0(NativeImageGenerator.java:476)
	at java.base/java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1407)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)
Error: Image build request failed with exit status 1
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  6.660 s
[INFO] Finished at: 2021-01-29T10:30:25Z
[INFO] ------------------------------------------------------------------------

Raw output from gcc -v

GraalVM wrapper script for clang
GraalVM version: 21.0.0
running: /home/paul/.sdkman/candidates/java/21.0.0.r11-grl/lib/llvm/bin/clang -v
clang version 10.0.0 (GraalVM.org llvmorg-10.0.0-4-g22d2637565-bg83994d0b4b 22d26375659ee388e18a96bf6b34e56299f75efc)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/paul/.sdkman/candidates/java/21.0.0.r11-grl/lib/llvm/bin
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Candidate multilib: x32;@mx32
Selected multilib: .;@m64
@olpaw
Copy link
Member

olpaw commented Jan 29, 2021

@cloudpaul you are not using a real gcc here. You are using the GraalVM wrapper script for clang which is used to build C/C++ sources into llvm bitcode (@fmorcos). Please ensure you do not have GraalVM wrappers on the PATH when you use native-image. Usually the native compiler resides in /usr/bin or /usr/lib64/ccache. The proper output of gcc -v should be something like

Using built-in specs.
COLLECT_GCC=/usr/bin/gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/10/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,objc,obj-c++,ada,go,d,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --enable-offload-targets=nvptx-none --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 10.2.1 20201125 (Red Hat 10.2.1-9) (GCC) 

Note that if you build with -H:+TraceNativeToolUsage native-image will show you all interaction with the native-compiler (query code compilation & linking). This is handy for debugging. Also you can use --native-compiler-path=<path-to-gcc> to ensure a specific version of gcc is used by native-image.

@olpaw
Copy link
Member

olpaw commented Jan 29, 2021

Note that when I force native-image to use a real clang everything works exactly as it should.

native-image -jar ~/OLabs/issues/HelloMaven/target/app-1.0-SNAPSHOT.jar --native-compiler-path=/usr/lib64/ccache/clang --native-image-info
[app-1.0-SNAPSHOT:43415]    classlist:   2,360.20 ms,  0.96 GB
[app-1.0-SNAPSHOT:43415]        (cap):   1,084.96 ms,  0.96 GB
[app-1.0-SNAPSHOT:43415]        setup:   4,387.68 ms,  0.96 GB
# Building image for target platform: org.graalvm.nativeimage.Platform$LINUX_AMD64
# Using native toolchain:
#   Name: Clang C++ Compiler (clang)
#   Vendor: llvm
#   Version: 11.0.0
#   Target architecture: x86_64
#   Path: /usr/lib64/ccache/clang
# Using CLibrary: com.oracle.svm.core.posix.linux.libc.GLibC
[app-1.0-SNAPSHOT:43415]     (clinit):     229.83 ms,  1.72 GB
# Static libraries:
#   ../../graal/sdk/mxbuild/linux-amd64/GRAALVM_354F894C6A_JAVA11/graalvm-354f894c6a-java11-21.1.0-dev/lib/svm/clibraries/linux-amd64/liblibchelper.a
#   ../../graal/sdk/mxbuild/linux-amd64/GRAALVM_354F894C6A_JAVA11/graalvm-354f894c6a-java11-21.1.0-dev/lib/static/linux-amd64/glibc/libnet.a
#   ../../graal/sdk/mxbuild/linux-amd64/GRAALVM_354F894C6A_JAVA11/graalvm-354f894c6a-java11-21.1.0-dev/lib/static/linux-amd64/glibc/libnio.a
#   ../../graal/sdk/mxbuild/linux-amd64/GRAALVM_354F894C6A_JAVA11/graalvm-354f894c6a-java11-21.1.0-dev/lib/static/linux-amd64/glibc/libjava.a
#   ../../graal/sdk/mxbuild/linux-amd64/GRAALVM_354F894C6A_JAVA11/graalvm-354f894c6a-java11-21.1.0-dev/lib/static/linux-amd64/glibc/libfdlibm.a
#   ../../graal/sdk/mxbuild/linux-amd64/GRAALVM_354F894C6A_JAVA11/graalvm-354f894c6a-java11-21.1.0-dev/lib/static/linux-amd64/glibc/libzip.a
#   ../../graal/sdk/mxbuild/linux-amd64/GRAALVM_354F894C6A_JAVA11/graalvm-354f894c6a-java11-21.1.0-dev/lib/svm/clibraries/linux-amd64/libjvm.a
# Other libraries: pthread,dl,z,rt
[app-1.0-SNAPSHOT:43415]   (typeflow):   5,330.08 ms,  1.72 GB
[app-1.0-SNAPSHOT:43415]    (objects):   4,723.38 ms,  1.72 GB
[app-1.0-SNAPSHOT:43415]   (features):     262.92 ms,  1.72 GB
[app-1.0-SNAPSHOT:43415]     analysis:  10,828.13 ms,  1.72 GB
[app-1.0-SNAPSHOT:43415]     universe:     438.41 ms,  1.72 GB
[app-1.0-SNAPSHOT:43415]      (parse):   1,939.96 ms,  1.73 GB
[app-1.0-SNAPSHOT:43415]     (inline):   1,268.87 ms,  1.73 GB
[app-1.0-SNAPSHOT:43415]    (compile):  16,059.42 ms,  3.21 GB
[app-1.0-SNAPSHOT:43415]      compile:  19,995.13 ms,  3.21 GB
[app-1.0-SNAPSHOT:43415]        image:   1,454.77 ms,  3.21 GB
[app-1.0-SNAPSHOT:43415]        write:     239.58 ms,  3.21 GB
[app-1.0-SNAPSHOT:43415]      [total]:  39,909.94 ms,  3.21 GB

@olpaw olpaw closed this as completed Jan 29, 2021
@cloudpaul
Copy link
Author

Ah, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants