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.28k stars 1.63k forks source link

[LLVM] Invalid bitcode: recursive PointerType #4735

Open ekmett opened 2 years ago

ekmett commented 2 years ago

Describe GraalVM and your environment :

 Java HotSpot(TM) 64-Bit Server VM (11.0.11+9-LTS-jvmci-21.1-b05) for bsd-amd64 JRE (11.0.11+9-LTS-jvmci-21.1-b05), built on Apr 13 2021 09:11:08 by "graal" with gcc 4.2.1 Compatible Apple LLVM 11.0.0 (clang-1100.0.33.17)

Have you verified this issue still happens when using the latest snapshot? You can find snapshot builds here: https://github.com/graalvm/graalvm-ce-dev-builds/releases

Describe the issue Attempting to build the fairly minimal example at github.com/ekmett/fish causes the following issue:

air:~/fish $ make run
mkdir -p target
clang --target=x86_64-apple-darwin src/stub.c -S -emit-llvm -o target/stub.ll
llvm-as target/stub.ll -o=target/stub.bc
cargo rustc --target=x86_64-apple-darwin --release --lib -- --emit=llvm-bc
   Compiling fish v0.1.0 (/Users/ekmett/fish)
    Finished release [optimized] target(s) in 4.52s
llvm-link target/stub.bc target/x86_64-apple-darwin/release/deps/fish.bc -o=target/fish.bc
/Users/ekmett/.sdkman/candidates/java/current/bin/lli --lib `rustc --print sysroot`/lib/libstd-* target/fish.bc
Invalid bitcode: recursive PointerType
make: *** [run] Error 1

A clear and concise description of the issue.

How to compile the LLVM bitcode that causes the problem

air:~/fish $ clang --version
Homebrew clang version 14.0.6
Target: arm64-apple-darwin20.6.0
Thread model: posix
InstalledDir: /opt/homebrew/opt/llvm/bin
air:~/fish $ rustc --version
rustc 1.64.0-nightly (f8588549c 2022-07-18)

Code snippet or code repository that reproduces the problem

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

Build steps are contained in the Makefile in that linked repository. (Some directory names in variable bindings at the top of the Makefile need to change.)

Expected behavior I expect it to print:

link start!

when run, instead of complaining about

Invalid bitcode: recursive PointerType.

Additional context

I basically assembled this repository from the suggestions posted in

https://michaelbh.com/blog/graalvm-and-rust-1/

and

the description of how rust can run on sulong from the graal documentation.

oubidar-Abderrahim commented 2 years ago

Hi, Could you please test with the latest available release 22.1?

ekmett commented 2 years ago

With 22.1.0.r17 I get an even scarier error when targeting either aarch64-apple-darwin or x86_64-apple-darwin:

mkdir -p target
clang --target=x86_64-apple-darwin src/stub.c -S -emit-llvm -o target/stub.ll
llvm-as target/stub.ll -o=target/stub.bc
cargo rustc --target=x86_64-apple-darwin --release --lib -- --emit=llvm-bc
   Compiling fish v0.1.0 (/Users/ekmett/fish)
    Finished release [optimized] target(s) in 4.46s
llvm-link target/stub.bc target/x86_64-apple-darwin/release/deps/fish.bc -o=target/fish.bc
/Users/ekmett/.sdkman/candidates/java/current/bin/lli --experimental-options --llvm.verifyBitcode=false --lib `rustc --print sysroot`/lib/libstd-* target/fish.bc
ERROR: com.oracle.truffle.api.CompilerDirectives$ShouldNotReachHere
org.graalvm.polyglot.PolyglotException: com.oracle.truffle.api.CompilerDirectives$ShouldNotReachHere
    at com.oracle.truffle.api.CompilerDirectives.shouldNotReachHere(CompilerDirectives.java:570)
    at com.oracle.truffle.api.CompilerDirectives.shouldNotReachHere(CompilerDirectives.java:490)
    at com.oracle.truffle.llvm.parser.factories.UnknownBasicPlatformCapability.getVAListType(UnknownBasicPlatformCapability.java:78)
    at com.oracle.truffle.llvm.parser.factories.BasicNodeFactory.<init>(BasicNodeFactory.java:382)
    at com.oracle.truffle.llvm.nativemode.NativeConfiguration.createNodeFactory(NativeConfiguration.java:69)
    at com.oracle.truffle.llvm.runtime.pthread.LLVMPThreadContext.lambda$new$0(LLVMPThreadContext.java:92)
    at com.oracle.truffle.llvm.runtime.LLVMLanguage.lambda$createCachedCallTarget$0(LLVMLanguage.java:714)
    at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1708)
    at com.oracle.truffle.llvm.runtime.LLVMLanguage.createCachedCallTarget(LLVMLanguage.java:714)
    at com.oracle.truffle.llvm.runtime.pthread.LLVMPThreadContext.<init>(LLVMPThreadContext.java:91)
    at com.oracle.truffle.llvm.runtime.LLVMContext.<init>(LLVMContext.java:243)
    at com.oracle.truffle.llvm.runtime.LLVMLanguage.createContext(LLVMLanguage.java:367)
    at com.oracle.truffle.llvm.runtime.LLVMLanguage.createContext(LLVMLanguage.java:90)
    at com.oracle.truffle.api.LanguageAccessor$LanguageImpl.createEnvContext(LanguageAccessor.java:263)
    at com.oracle.truffle.polyglot.PolyglotLanguageContext.ensureCreated(PolyglotLanguageContext.java:587)
    at com.oracle.truffle.polyglot.PolyglotLanguageContext.ensureInitialized(PolyglotLanguageContext.java:666)
    at com.oracle.truffle.polyglot.PolyglotContextImpl.eval(PolyglotContextImpl.java:1324)
    at com.oracle.truffle.polyglot.PolyglotContextDispatch.eval(PolyglotContextDispatch.java:63)
    at org.graalvm.polyglot.Context.eval(Context.java:399)
    at com.oracle.truffle.llvm.launcher.LLVMLauncher.execute(LLVMLauncher.java:255)
    at com.oracle.truffle.llvm.launcher.LLVMLauncher.launch(LLVMLauncher.java:76)
    at org.graalvm.launcher.AbstractLanguageLauncher.launch(AbstractLanguageLauncher.java:296)
    at org.graalvm.launcher.AbstractLanguageLauncher.launch(AbstractLanguageLauncher.java:121)
    at com.oracle.truffle.llvm.launcher.LLVMLauncher.main(LLVMLauncher.java:53)
Caused by: Attached Guest Language Frames (0)
Internal GraalVM error, please report at https://github.com/oracle/graal/issues/.
make: *** [run-unverified] Error 1
PanagiotisDrakatos commented 2 years ago

@ekmett @oubidar-Abderrahim Do you find any solution? i am facing the same issue

rschatz commented 2 years ago

That last error (with the UnknownBasicPlatformCapability) is because darwin-aarch64 is not supported by the LLVM runtime in 22.1. It was a packaging error that the lli binary is even shipped there. It should work on 22.2. I don't think it has anything to do with the original issue.

The Invalid bitcode: recursive PointerType error is probably a bug on our side. I'll look into it.

PanagiotisDrakatos commented 2 years ago

@rschatz

Let me describe to you my steps its similar to the question

I compile my rust cargo project with this

RUSTFLAGS="--emit=llvm-bc" cargo build --release

The issue is that the bitcode for the current module and its dependencies are generated separately (in target/release/deps/my_liblib.bc and target/release/deps/external_lib.bc. They're only combined when the actual compiled library is generated.

We don't want to link all of the standard libraries. We really only need std and its dependencies: proc_macro isn't needed here since we are compiling to a binary, not a proc-macro. We also need to link with either proc_abort or panic_unwind, matching it up with the unwind codegen setting we chose. The default is unwinding, so let's delete the other one, proc_abort. Let's send those libraries to the chopping block: rm target/x86_64-unknown-linux-gnu/release/deps/{panic_abort,proc_macro}-*.bc

we delete the unnecessary files rm target/x86_64-unknown-linux-gnu/release/deps/{panic_abort,proc_macro}-*.bc

and finally, we link all together to embed bc file llvm-link target/x86_64-unknown-linux-gnu/release/deps/*.bc > finally.bc

The error that i get when calling from graal is Invalid bitcode: recursive PointerType

Please if possible inform me here about this issue when it will be fixed I appreciate your effort and thanks in advance

s1ck commented 1 year ago

My issue might be related: https://github.com/oracle/graal/issues/5201