polyglot-compiler / JLang

JLang: Ahead-of-time compilation of Java programs to LLVM
http://polyglot-compiler.github.io/JLang/
Other
287 stars 30 forks source link

compile_ll.sh throws 'undefined reference' error #66

Closed ghost closed 4 years ago

ghost commented 4 years ago

I have a multi-file Java application, and I consolidated all Java files to a single file (called BT.java).

I could run it using JDK without any problem: $ javac BT.java $ java BT -np8 CLASS=A

... the application will work fine ...

But couldn't run it with JLang: $ ./bin/jlangc BT.java $ ./bin/compile_ll.sh BT.ll

/tmp/BT-b2f8ff.o:(.data+0x100): undefined reference to `Polyglot_java_lang_Thread_init__Ljava_lang_ThreadGroup_2Ljava_lang_Runnable_2Ljava_lang_String_2J'
/tmp/BT-b2f8ff.o:(.data+0x108): undefined reference to `Polyglot_java_lang_Thread_init__Ljava_lang_ThreadGroup_2Ljava_lang_Runnable_2Ljava_lang_String_2JLjava_security_AccessControlContext_2Z'
/tmp/BT-b2f8ff.o:(.data+0x2100): undefined reference to `Polyglot_java_lang_Thread_init__Ljava_lang_ThreadGroup_2Ljava_lang_Runnable_2Ljava_lang_String_2J'
/tmp/BT-b2f8ff.o:(.data+0x2108): undefined reference to `Polyglot_java_lang_Thread_init__Ljava_lang_ThreadGroup_2Ljava_lang_Runnable_2Ljava_lang_String_2JLjava_security_AccessControlContext_2Z'
/tmp/BT-b2f8ff.o:(.data+0x2790): undefined reference to `Polyglot_java_lang_Thread_init__Ljava_lang_ThreadGroup_2Ljava_lang_Runnable_2Ljava_lang_String_2J'
/tmp/BT-b2f8ff.o:(.data+0x2798): undefined reference to `Polyglot_java_lang_Thread_init__Ljava_lang_ThreadGroup_2Ljava_lang_Runnable_2Ljava_lang_String_2JLjava_security_AccessControlContext_2Z'
/tmp/BT-b2f8ff.o:(.data+0x2ea0): undefined reference to `Polyglot_java_lang_Thread_init__Ljava_lang_ThreadGroup_2Ljava_lang_Runnable_2Ljava_lang_String_2J'
/tmp/BT-b2f8ff.o:(.data+0x2ea8): undefined reference to `Polyglot_java_lang_Thread_init__Ljava_lang_ThreadGroup_2Ljava_lang_Runnable_2Ljava_lang_String_2JLjava_security_AccessControlContext_2Z'
/tmp/BT-b2f8ff.o:(.data+0x3470): undefined reference to `Polyglot_java_lang_Thread_init__Ljava_lang_ThreadGroup_2Ljava_lang_Runnable_2Ljava_lang_String_2J'
/tmp/BT-b2f8ff.o:(.data+0x3478): undefined reference to `Polyglot_java_lang_Thread_init__Ljava_lang_ThreadGroup_2Ljava_lang_Runnable_2Ljava_lang_String_2JLjava_security_AccessControlContext_2Z'
/tmp/BT-b2f8ff.o:(.data+0x3a40): undefined reference to `Polyglot_java_lang_Thread_init__Ljava_lang_ThreadGroup_2Ljava_lang_Runnable_2Ljava_lang_String_2J'
/tmp/BT-b2f8ff.o:(.data+0x3a48): undefined reference to `Polyglot_java_lang_Thread_init__Ljava_lang_ThreadGroup_2Ljava_lang_Runnable_2Ljava_lang_String_2JLjava_security_AccessControlContext_2Z'
/tmp/BT-b2f8ff.o:(.data+0x4210): undefined reference to `Polyglot_java_lang_Thread_init__Ljava_lang_ThreadGroup_2Ljava_lang_Runnable_2Ljava_lang_String_2J'
/tmp/BT-b2f8ff.o:(.data+0x4218): undefined reference to `Polyglot_java_lang_Thread_init__Ljava_lang_ThreadGroup_2Ljava_lang_Runnable_2Ljava_lang_String_2JLjava_security_AccessControlContext_2Z'
clang-5.0: error: linker command failed with exit code 1 (use -v to see invocation)
Wrote compiled binary to BT.o

I guess JLang couldn't link some applications properly.


dz333 commented 4 years ago

Sorry for just getting to this.

I think the issue is with your command compiling the *.java file. You should be compiling the java file with the classpath option pointing to the JDK files that get compiled as part of the JLang make. ./bin/jlangc -cp jdk/out/classes BT.java

This will compile it with the right reference names so that, once you link against our JDK library it finds these references (I tried it with your code example and linking succeeds).

However, I did run into problems actually running your code; I think mashing everything into one file might be finding some sort of edge case in our compiler (since it does run fine under normal java). I'm looking into what exactly is causing that problem.

dz333 commented 4 years ago

Yeah i just figured out the issue.

Jlang actually can't properly compile and reference multiple classes within a single source file. You can create nested classes that are properly accessible but since you have multiple top-level classes in a single source file, at runtime the classes don't properly refer to each other.

This causes a runtime error when trying to initialize the Timer field of BTBase, for instance.

I would recommend changing this back to a multi-file project.

ghost commented 4 years ago

Hello,

Thank you very much for your response, I will give it a shot.