brenhinkeller / StaticTools.jl

Enabling StaticCompiler.jl-based compilation of (some) Julia code to standalone native binaries by avoiding GC allocations and llvmcall-ing all the things!
MIT License
167 stars 11 forks source link

llvmio.jl is using incorrect declarations #33

Open vtjnash opened 1 year ago

vtjnash commented 1 year ago

It looks like many of the llvmcalls have incorrect definitions, atributes, types, ABIs, or other errors. These seem like they really should be using @ccall instead to let Julia handle those issues. I noticed this because it crashed in PkgEval with an LLVM verifier error.

brenhinkeller commented 1 year ago

Ah yeah, I think there's at least one more I still have wrong in there. As far as I understand @ccall is still not really StaticCompiler-able though, which is a must-have here.

If you have any pointers for which calls still have errors and what, that would be much appreciated -- but no worries if not; I know you have important things to do!

brenhinkeller commented 1 year ago

Oh, maybe @ccall does compile now, that would be nice!

julia> using StaticCompiler, StaticTools

julia> function hello()
           s = c"Hello, world!\n"
           p = pointer(s)
           GC.@preserve s @ccall printf(p::Ptr{UInt8})::Cint
       end
hello (generic function with 1 method)

julia> compile_executable(hello, (), "./")
"/Users/cbkeller/hello"

shell> ./hello
Hello, world!
vtjnash commented 1 year ago

A few I noticed specifically: incorrect attributes (e.g. nocapture on putc), incorrect ABI (printf is varargs, ftell may return either i64 or i64* depending on the platform ABI, fputc takes an int, it is usually illegal to pass i16 directly to vararg functions like fprintf, malloc takes an Int not Int64, similar issues for memset)

brenhinkeller commented 1 year ago

Thanks!

brenhinkeller commented 1 year ago

34 may (?) be enough to fix the pkgeval failures for now, but I'll leave this open until I get a chance to try switching to @ccall