JuliaLang / julia

The Julia Programming Language
https://julialang.org/
MIT License
45.71k stars 5.49k forks source link

julia 1.11.0 beta 1 build error on FreeBSD #54123

Open oikumene opened 6 months ago

oikumene commented 6 months ago

While trying to build julia on FreeBSD stable/14, I encountered the following error and cannot resolve it.

gmake[1]: Leaving directory '/wrkdirs/usr/ports/lang/julia/work/julia-1.11.0-beta1/src'
gmake[1]: Entering directory '/wrkdirs/usr/ports/lang/julia/work/julia-1.11.0-beta1'
Warning: git information unavailable; versioning information limited
 cd /wrkdirs/usr/ports/lang/julia/work/julia-1.11.0-beta1/base && /wrkdirs/usr/ports/lang/julia/work/julia-1.11.0-beta1/usr/bin/julia -C "generic"  --output-ji /wrkdirs/usr/ports/lang/julia/work/julia-1.11.0-beta1/usr/lib/julia/corecompiler.ji.tmp --startup-file=no --warn-overwrite=yes -g0 -O0 compiler/compiler.jl
: CommandLine Error: Option 'debug-counter' registered more than once!
LLVM ERROR: inconsistency in registered CommandLine options

The make argument is as below:

MAKE_ARGS+=     VERBOSE=1 NO_GIT=1 \
                USE_BINARYBUILDER=0 \
                prefix=${PREFIX} \
                JCXXFLAGS="${CXXFLAGS}" \
                USE_GPL_LIBS=0 \
                ARCH=x86_64 \
                JULIA_CPU_TARGET=generic \
                USE_SYSTEM_CURL=1 \
                USE_SYSTEM_DSFMT=1 \
                USE_SYSTEM_GMP=1 \
                USE_SYSTEM_OPENLIBM=1 \
                USE_SYSTEM_LAPACK=1 \
                USE_SYSTEM_LIBGIT2=1 \
                USE_SYSTEM_LIBSSH2=1 \
                USE_SYSTEM_MBEDTLS=1 \
                USE_SYSTEM_MPFR=1 \
                USE_SYSTEM_PATCHELF=1 \
                USE_SYSTEM_PCRE=1 \
                USE_SYSTEM_UTF8PROC=1 \
                USE_SYSTEM_P7ZIP=1 \
                USE_SYSTEM_BLAS=1 \
                USE_SYSTEM_NGHTTP2=1 \
                USE_SYSTEM_CSL=1 \
                USE_SYSTEM_LIBUNWIND=1 \
                CC=${CC} \
                CXX=${CXX}
oikumene commented 6 months ago

Building with llvm18, I got following stack trace:

[57107] signal 6 (65543): Abort trap
in expression starting at none:0
thr_kill at /lib/libc.so.7 (unknown line)
_raise at /lib/libc.so.7 (unknown line)
abort at /lib/libc.so.7 (unknown line)
_ZN4llvm18report_fatal_errorERKNS_5TwineEb.cold at /wrkdirs/usr/ports/lang/juli
a/work/julia-1.11.0-beta1/usr/bin/../lib/libjulia-internal.so.1.11 (unknown line)
_ZN4llvm18report_fatal_errorEPKcb at /wrkdirs/usr/ports/lang/julia/work/julia-1.11.0-beta1/usr/bin/../lib/libjulia-internal.so.1.11 (unknown line)
_ZN12_GLOBAL__N_117CommandLineParser9addOptionEPN4llvm2cl6OptionEPNS2_10SubCommandE at /wrkdirs/usr/ports/lang/julia/work/julia-1.11.0-beta1/usr/bin/../lib/libjulia-internal.so.1.11 (unknown line)
_ZN4llvm2cl6Option11addArgumentEv at /wrkdirs/usr/ports/lang/julia/work/julia-1.11.0-beta1/usr/bin/../lib/libjulia-internal.so.1.11 (unknown line)
_ZN4llvm12DebugCounter8instanceEv.part.0 at /wrkdirs/usr/ports/lang/julia/work/julia-1.11.0-beta1/usr/bin/../lib/libjulia-internal.so.1.11 (unknown line)
_ZN4llvm2cl20getRegisteredOptionsERNS0_10SubCommandE at /wrkdirs/usr/ports/lang/julia/work/julia-1.11.0-beta1/usr/bin/../lib/libjulia-internal.so.1.11 (unknown line)
jl_init_llvm at /wrkdirs/usr/ports/lang/julia/work/julia-1.11.0-beta1/src/codegen.cpp:9965
jl_init_codegen_impl at /wrkdirs/usr/ports/lang/julia/work/julia-1.11.0-beta1/src/codegen.cpp:10059
_finish_julia_init at /wrkdirs/usr/ports/lang/julia/work/julia-1.11.0-beta1/src/init.c:857
jl_repl_entrypoint at /wrkdirs/usr/ports/lang/julia/work/julia-1.11.0-beta1/src/jlapi.c:1053
main at /wrkdirs/usr/ports/lang/julia/work/julia-1.11.0-beta1/usr/bin/julia (unknown line)
__libc_start1 at /lib/libc.so.7 (unknown line)
_start at /wrkdirs/usr/ports/lang/julia/work/julia-1.11.0-beta1/usr/bin/julia (unknown line)
Allocations: 0 (Pool: 0; Big: 0); GC: 0
giordano commented 6 months ago

LLVM 18? Julia master doesn't even support LLVM 17 yet, v1.11 only supports LLVM 16. But I take you're trying to build Julia with an external and unsupported llvm version, which based on googling the error message

LLVM ERROR: inconsistency in registered CommandLine options

is very likely the cause of your problem.

oikumene commented 6 months ago

By "llvm18", I wanted to say that I built julia with clang18. I always used llvm shipped with julia. But I looked into the wrong log file, and the above error message was built by gcc13. (building julia with clang on FreeBSD has the same problem as #52067 until recent FreeBSD-current. I will try it later)

I found this conversation. It is rather old but describes the problem I encountered.

So, there is three instance of initCommonOptions(), one in libLLVM-16jl.so, one in libjulia-codegen.so and one in libjulia-internal.so, which make initCommonOptions() called many times. The solution I took is to remove linking of static LLVM libraries from libjulia-internal.so and libjulia-codegen.so, and link libLLVM-16jl.so to libjulia-internal.so too. As libLLVM-16jl.so links all the static LLVM libraries, the code in the three libraries may call LLVM functions while initCommonOptions() is called only once in libLLVM-16jl.so.