BinaryBuilder for Deldir

I’m trying out BinaryBuilder for my Deldir package that wraps Fortran code from the R package deldir.

On my own computer I can create a working shared object file with the following Bash commands extracted from the R package:

for f in `ls *.f | sed "s/\.f$//"`; do
    gfortran -fpic -o2 -pipe -g -c $f.f -o $f.o
done

clang -shared -o libdeldir.so *.o -lgfortran -lm -lquadmath

In fact, I don’t even need the last three -l commands.

When running something similar with BinaryBuilder I get no compilation errors, but ccall’ing libdeldir.so make Julia segfault.
Even after a lot of searching and trying different compiler tricks I have no luck in creating a working so file.
With the lack of compilation errors I don’t really know how to move forward,

I have made a DeldirBuilder repo with the build_tarballs.jl script.
For easy reference, my Bash script for compilation is

for f in `ls *.f | sed "s/\.f$//"`; do
    ${FC} -fpic -o2 -pipe -g -c $f.f -o $f.o
done

mkdir -p "${prefix}/lib"
LDFLAGS="-lgfortran -lm -lquadmath"
${CC} -shared -o ${prefix}/lib/libdeldir.${dlext} *.o 

BTW I do get errors with older versions of GCC, but e.g. GCC 7 is okay:

julia --color=yes build_tarballs.jl --verbose --debug x86_64-linux-gnu-gcc7

I have asked a similar question on the bindeps2 channel on Slack. Sorry for crosspostning, but I haven’t succeeded with the suggestions I got there.

I don’t know if this fixes the issue, but you’re not using the LDFLAGS variable after you set it.

Also, the script that you show here is different from what it’s now on GitHub, for example there you don’t create the $prefix/lib directory (which leads to an error when you try to compile and put the output there).

Anyway, even without using LDFLAGS at all, I cannot reproduce your segmentation fault (64-bit GNU/Linux systems here). I’m trying to build the library with the following script:

script = raw"""
cd $WORKSPACE/srcdir/deldir/src

for f in `ls *.f | sed "s/\.f$//"`; do
    ${FC} -fpic -o2 -pipe -g -c $f.f -o $f.o
done

mkdir -p "${prefix}/lib"
${CC} -shared -o ${prefix}/lib/libdeldir.${dlext} *.o
"""

The rest of the build_tarballs.jl is the one on GitHub. I then copy the resulting libdeldir.so to deps/deldir.so in the Julia package directory and run the tests. I get the following error:

ERROR: LoadError: InexactError: trunc(Int32, 100)
Stacktrace:
 [1] throw_inexacterror(::Symbol, ::Any, ::Int64) at ./boot.jl:583
 [2] checked_trunc_sint at ./boot.jl:605 [inlined]
 [3] toInt32 at ./boot.jl:642 [inlined]
 [4] Type at ./boot.jl:732 [inlined]
 [5] convert at ./number.jl:7 [inlined]
 [6] Type at ./refvalue.jl:8 [inlined]
 [7] convert at ./refpointer.jl:51 [inlined]
 [8] cconvert at ./essentials.jl:355 [inlined]
 [9] #deldirwrapper#1(::Float64, ::Function, ::Array{Float64,1}, ::Array{Float64,1}, ::Array{Float64,1}) at /home/mose/.julia/dev/Deldir/src/wrapper.jl:151
 [10] deldirwrapper at /home/mose/.julia/dev/Deldir/src/wrapper.jl:141 [inlined]
 [11] voronoiarea at /home/mose/.julia/dev/Deldir/src/misc.jl:9 [inlined] (repeats 2 times)
 [12] top-level scope at none:0
 [13] include at ./boot.jl:326 [inlined]
 [14] include_relative(::Module, ::String) at ./loading.jl:1038
 [15] include(::Module, ::String) at ./sysimg.jl:29
 [16] include(::String) at ./client.jl:403
 [17] top-level scope at none:0
in expression starting at /home/mose/.julia/dev/Deldir/test/runtests.jl:9
ERROR: Package Deldir errored during testing

Older compared to what? The default compiler on GNU/Linux systems with BinaryBuilder is GCC 4.

Thanks a lot for trying it out – it’s super weird that it works for you.

Sorry about the mismatch between the posted script and the one on GitHub! When experimenting I did create the lib folder.

Now that I think about it I suppose the segfault can be caused by using a wrong architecture. I use “x86_64-linux-gnu” since this is in “OS” of versioninfo:

julia> versioninfo()
Julia Version 1.1.0
Commit 80516ca202* (2019-01-21 21:24 UTC)
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: Intel(R) Core(TM) i5-8265U CPU @ 1.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.1 (ORCJIT, skylake)

Have I understood this correctly?

Yes, your platform (and also mine) is “x86_64-linux-gnu”, you should create the build for that platform if you want to test locally

PS:

for f in `ls *.f | sed "s/\.f$//"`; do
  ${FC} -fpic -o2 -pipe -g -c $f.f -o $f.o
done

is better written as

for f in *.f; do
  ${FC} -fpic -o2 -pipe -g -c "${f}" -o "$(basename "${f}" .f}.o"
done

It’s discouraged to use the output of ls

I’ll give it another go tomorrow – thanks a lot for you help!
Also thanks for the bash tips :slight_smile:

Regarding the compiler version I meant compared to the default version 4. But since that also works for you I suppose it’s not a real problem.

“works” in the sense that I don’t get the segmentation fault, but the test fails because of the error posted above.

I think I have found out why we get different results: The tests did not get to the ccall (now I have updated them so they do).
@giordano : Does your so file work with the following commands?

using Deldir
x = rand(8); y = rand(8);
A = voronoiarea(x, y)

I get this segfault

signal (11): Segmentation fault                                                                   [9/885]
in expression starting at /home/robert/.julia/dev/Deldir/startup.jl:9
unsafe_convert at ./pointer.jl:65 [inlined]
pointer at ./abstractarray.jl:883 [inlined]
unsafe_convert at ./refpointer.jl:66 [inlined]
unsafe_convert at ./refpointer.jl:48 [inlined]
#deldirwrapper#1 at /home/robert/.julia/dev/Deldir/src/wrapper.jl:151
unknown function (ip: 0x7f11fc8d3008)
jl_fptr_trampoline at /usr/local/julia/julia-1.1.0/src/gf.c:1864
jl_apply_generic at /usr/local/julia/julia-1.1.0/src/gf.c:2219
deldirwrapper at /home/robert/.julia/dev/Deldir/src/wrapper.jl:141 [inlined]
voronoiarea at /home/robert/.julia/dev/Deldir/src/misc.jl:9 [inlined]
voronoiarea at /home/robert/.julia/dev/Deldir/src/misc.jl:9
jl_fptr_trampoline at /usr/local/julia/julia-1.1.0/src/gf.c:1864
jl_apply_generic at /usr/local/julia/julia-1.1.0/src/gf.c:2219
do_call at /usr/local/julia/julia-1.1.0/src/interpreter.c:323
eval_value at /usr/local/julia/julia-1.1.0/src/interpreter.c:411
eval_stmt_value at /usr/local/julia/julia-1.1.0/src/interpreter.c:362 [inlined]
eval_body at /usr/local/julia/julia-1.1.0/src/interpreter.c:773
jl_interpret_toplevel_thunk_callback at /usr/local/julia/julia-1.1.0/src/interpreter.c:885
unknown function (ip: 0xfffffffffffffffe)
unknown function (ip: 0x7f11c102878f)
unknown function (ip: 0xffffffffffffffff)
jl_interpret_toplevel_thunk at /usr/local/julia/julia-1.1.0/src/interpreter.c:894
jl_toplevel_eval_flex at /usr/local/julia/julia-1.1.0/src/toplevel.c:764
jl_parse_eval_all at /usr/local/julia/julia-1.1.0/src/ast.c:883
jl_load at /usr/local/julia/julia-1.1.0/src/toplevel.c:826
include at ./boot.jl:326 [inlined]
include_relative at ./loading.jl:1038
include at ./sysimg.jl:29
jl_fptr_trampoline at /usr/local/julia/julia-1.1.0/src/gf.c:1864
jl_apply_generic at /usr/local/julia/julia-1.1.0/src/gf.c:2219
include at ./client.jl:403
jl_fptr_trampoline at /usr/local/julia/julia-1.1.0/src/gf.c:1864
jl_apply_generic at /usr/local/julia/julia-1.1.0/src/gf.c:2219
do_call at /usr/local/julia/julia-1.1.0/src/interpreter.c:323
eval_value at /usr/local/julia/julia-1.1.0/src/interpreter.c:411
eval_stmt_value at /usr/local/julia/julia-1.1.0/src/interpreter.c:362 [inlined]
eval_body at /usr/local/julia/julia-1.1.0/src/interpreter.c:773
jl_interpret_toplevel_thunk_callback at /usr/local/julia/julia-1.1.0/src/interpreter.c:885
unknown function (ip: 0xfffffffffffffffe)
unknown function (ip: 0x7f11c01222bf)
unknown function (ip: 0xffffffffffffffff)
jl_interpret_toplevel_thunk at /usr/local/julia/julia-1.1.0/src/interpreter.c:894
jl_toplevel_eval_flex at /usr/local/julia/julia-1.1.0/src/toplevel.c:764
jl_toplevel_eval_in at /usr/local/julia/julia-1.1.0/src/toplevel.c:793
eval at ./boot.jl:328
jl_apply_generic at /usr/local/julia/julia-1.1.0/src/gf.c:2219
eval_user_input at /usr/local/julia/julia-1.1.0/usr/share/julia/stdlib/v1.1/REPL/src/REPL.jl:85
macro expansion at /usr/local/julia/julia-1.1.0/usr/share/julia/stdlib/v1.1/REPL/src/REPL.jl:117 [inlined]
#26 at ./task.jl:259
jl_apply_generic at /usr/local/julia/julia-1.1.0/src/gf.c:2219
jl_apply at /usr/local/julia/julia-1.1.0/src/julia.h:1571 [inlined]
start_task at /usr/local/julia/julia-1.1.0/src/task.c:572
unknown function (ip: 0xffffffffffffffff)
Allocations: 31039849 (Pool: 31033213; Big: 6636); GC: 65
[1]    28866 segmentation fault  julia

I get a segfault, too. Are you sure function signature is correct?

Edit: I had a look at the ccall and it does look correct to me at a quick glance.

1 Like

That turned out to be a spot on question! I am using different versions of the Fortran code in the DeldirBuilder and the Deldir repos :flushed:

A huge thank you @giordano ! I had starred myself blind at this problem.