Javacpp-presets: Crash when calling LLVMTargetMachineEmitToFile

Created on 2 Jan 2020  路  11Comments  路  Source: bytedeco/javacpp-presets

Hi,

When I pass the module to the LLVMTargetMachineEmitToFile api, the system crashes.

I'm on Mac OSX 10.15 using latest bytedeco llvm 9.0.0-1.5.2

Crash Log
Stack: [0x000070000c077000,0x000070000c177000], sp=0x000070000c175770, free space=1017k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C [libLLVM.dylib+0x23b47a] _ZN4llvm17PMTopLevelManager16addImmutablePassEPNS_13ImmutablePassE+0xca
C [libLLVM.dylib+0x23ac6d] _ZN4llvm17PMTopLevelManager12schedulePassEPNS_4PassE+0x84d
C [libLLVM.dylib+0x23ab9a] _ZN4llvm17PMTopLevelManager12schedulePassEPNS_4PassE+0x77a
C [libLLVM.dylib+0x578a30] _ZN4llvm16TargetPassConfig7addPassEPNS_4PassEbb+0x1f0
C [libLLVM.dylib+0x578e40] _ZN4llvm16TargetPassConfig11addIRPassesEv+0xb0
C [libLLVM.dylib+0x176e24b] _ZN12_GLOBAL__N_113X86PassConfig11addIRPassesEv+0x2b
C [libLLVM.dylib+0x579612] _ZN4llvm16TargetPassConfig13addISelPassesEv+0xb2
C [libLLVM.dylib+0x39c7c9] _ZN4llvm17LLVMTargetMachine19addPassesToEmitFileERNS_6legacy15PassManagerBaseERNS_17raw_pwrite_streamEPS4_NS_13TargetMachine15CodeGenFileTypeEbPNS_17MachineModuleInfoE+0x89
C [libLLVM.dylib+0x14fcafa] _ZL21LLVMTargetMachineEmitP23LLVMOpaqueTargetMachineP16LLVMOpaqueModuleRN4llvm17raw_pwrite_streamE19LLVMCodeGenFileTypePPc+0x13a
C [libLLVM.dylib+0x14fc97d] LLVMTargetMachineEmitToFile+0xad
C [libjniLLVM.dylib+0x56e74] Java_org_bytedeco_llvm_global_LLVM_LLVMTargetMachineEmitToFile__Lorg_bytedeco_llvm_LLVM_LLVMTargetMachineRef_2Lorg_bytedeco_llvm_LLVM_LLVMModuleRef_2_3BI_3B+0xc4
j org.bytedeco.llvm.global.LLVM.LLVMTargetMachineEmitToFile(Lorg/bytedeco/llvm/LLVM/LLVMTargetMachineRef;Lorg/bytedeco/llvm/LLVM/LLVMModuleRef;[BI[B)I+0
j org.ballerinalang.nativeimpl.llvm.gen.LLVMTargetMachineEmitToFile.llvmTargetMachineEmitToFile(Lorg/ballerinalang/jvm/scheduling/Strand;Lorg/ballerinalang/jvm/values/MapValue;Lorg/ballerinalang/jvm/values/MapValue;Lorg/ballerinalang/jvm/values/ArrayValue;JLorg/ballerinalang/jvm/values/ArrayValue;)J+43
j ballerina.llvm.staticfunc.llvmTargetMachineEmitToFile(Lorg/ballerinalang/jvm/scheduling/Strand;Lorg/ballerinalang/jvm/values/MapValue;ZLorg/ballerinalang/jvm/values/MapValue;ZLorg/ballerinalang/jvm/values/ArrayValue;ZJZLorg/ballerinalang/jvm/values/ArrayValue;Z)J+103
j ballerina.compiler_backend_llvm.llvm_gen.createObjectFile(Lorg/ballerinalang/jvm/scheduling/Strand;Ljava/lang/String;ZLorg/ballerinalang/jvm/values/MapValue;Z)Ljava/lang/Object;+356
j ballerina.compiler_backend_llvm.llvm_gen.genPackage(Lorg/ballerinalang/jvm/scheduling/Strand;Lorg/ballerinalang/jvm/values/MapValue;ZLjava/lang/String;ZZZZZ)Ljava/lang/Object;+437
j ballerina.compiler_backend_llvm.main.generateObjFile(Lorg/ballerinalang/jvm/scheduling/Strand;Ljava/lang/String;ZLjava/lang/String;ZZZZZ)Ljava/lang/Object;+1056
j ballerina.compiler_backend_llvm.main.main(Lorg/ballerinalang/jvm/scheduling/Strand;Lorg/ballerinalang/jvm/values/ArrayValue;Z)Ljava/lang/Object;+346

question

All 11 comments

That sounds like a question about LLVM. You'll probably get more help
posting in their forums.

Hey saudet, I tried your sample as well. It fails the same. Can you please check?

Screenshot 2020-01-03 at 12 25 32

None of the samples call LLVMTargetMachineEmitToFile().

Yes. That is true. But the same error occurs when trying to run the sample.

Which one?

Works just fine for me:

$ sw_vers
ProductName:    Mac OS X
ProductVersion: 10.14.6
BuildVersion:   18G103
$ mvn -version
Apache Maven 3.6.2 (40f52333136460af0dc0d7232c0dc0bcf0d9e117; 2019-08-27T10:06:16-05:00)
Maven home: /usr/local/Cellar/maven/3.6.2/libexec
Java version: 1.8.0_232, vendor: AdoptOpenJDK, runtime: /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.14.6", arch: "x86_64", family: "mac"
$ cd /path/to/javacpp-presets/llvm/samples
$ mvn clean compile exec:java
[INFO] Scanning for projects...
[INFO] 
[INFO] -----------------------< org.bytedeco.llvm:fac >------------------------
[INFO] Building fac 1.5.2
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ fac ---
[INFO] Deleting /Users/samuel/projects/bytedeco/javacpp-presets/llvm/samples/target
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ fac ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Users/samuel/projects/bytedeco/javacpp-presets/llvm/samples/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ fac ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 6 source files to /Users/samuel/projects/bytedeco/javacpp-presets/llvm/samples/target/classes
[WARNING] /Users/samuel/projects/bytedeco/javacpp-presets/llvm/samples/Fac.java: /Users/samuel/projects/bytedeco/javacpp-presets/llvm/samples/Fac.java uses unchecked or unsafe operations.
[WARNING] /Users/samuel/projects/bytedeco/javacpp-presets/llvm/samples/Fac.java: Recompile with -Xlint:unchecked for details.
[INFO] 
[INFO] --- exec-maven-plugin:1.6.0:java (default-cli) @ fac ---
; ModuleID = 'fac_module'
source_filename = "fac_module"
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"

define i32 @fac(i32) {
entry:
  %"n == 0" = icmp eq i32 %0, 0
  br i1 %"n == 0", label %end, label %iffalse

iffalse:                                          ; preds = %entry
  %"n - 1" = add i32 %0, -1
  %"fac(n - 1)" = call i32 @fac(i32 %"n - 1")
  %"n * fac(n - 1)" = mul i32 %"fac(n - 1)", %0
  br label %end

end:                                              ; preds = %entry, %iffalse
  %result = phi i32 [ %"n * fac(n - 1)", %iffalse ], [ 1, %entry ]
  ret i32 %result
}

; Running fac(10) with JIT...
; Result: 3628800
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.950 s
[INFO] Finished at: 2020-01-03T06:06:09-06:00
[INFO] ------------------------------------------------------------------------

Thats strange. I get the above output that I have attached. Any idea why?

Maybe it's one of those new security issues that prevents LLVM from working? Try to run it with root privileges and if that works, then we'll need to figure out which security "feature" needs to be disabled.

I completely removed all llvm implementations and rust from my system. Then running this fixed the issue. May be my LibLLVM.dylib had a version mismatch. Now it is working. Thanks

Hum, that's strange. If this happens again, please set the "org.bytedeco.javacpp.logger.debug" system property to "true". With this, the libraries that it tries to load will get displayed on the console. It shouldn't try to load any from the system, unless it fails to load the ones from the JAR files.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Maurice-Betzel picture Maurice-Betzel  路  32Comments

archenroot picture archenroot  路  23Comments

archenroot picture archenroot  路  56Comments

thunterdb picture thunterdb  路  37Comments

siddharthmudgal picture siddharthmudgal  路  26Comments