savi-lang / savi

A fast language for programmers who are passionate about their craft.
BSD 3-Clause "New" or "Revised" License
155 stars 12 forks source link

Problems when building on DragonFly #380

Closed mneumann closed 1 year ago

mneumann commented 1 year ago

I struggle at the last link-step on DragonFly BSD:

clang14 -c -no-pie  -O3 -o build/llvm_ext.o build/llvm_ext.bc
clang14 -c -no-pie  -O3 -o build/llvm_ext_for_savi.o build/llvm_ext_for_savi.bc
clang14 -o build/savi-release -flto=thin -no-pie  -O3 \
        build/savi-release.o   \
        build/llvm_ext.o \
        build/llvm_ext_for_savi.o \
        -L/usr/local/lib \
        -lm -lgc-threaded -levent -lpcre \
        `/usr/local/llvm14/bin/llvm-config --libfiles --link-static` \
        `/usr/local/llvm14/bin/llvm-config --cxxflags --ldflags --libs  --system-libs --link-static`  \
        `ls /usr/local/llvm14/lib/libclang*.a` \
        `ls /usr/local/llvm14/lib/liblld*.a`

When I run it, it compains about symbols not found:

clang-14: warning: argument unused during compilation: '-no-pie' [-Wunused-command-line-argument]
warning: overriding the module target triple with x86_64-portbld-dragonfly6.2 [-Woverride-module]
1 warning generated.
clang-14: warning: argument unused during compilation: '-no-pie' [-Wunused-command-line-argument]
warning: overriding the module target triple with x86_64-portbld-dragonfly6.2 [-Woverride-module]
1 warning generated.
clang-14: warning: argument unused during compilation: '-no-pie' [-Wunused-command-line-argument]
/home/mneumann/savi/lib/clang/src/index.cr:13: error: undefined reference to 'clang_createIndex'
/home/mneumann/savi/lib/clang/src/translation_unit.cr:8: error: undefined reference to 'clang_defaultEditingTranslationUnitOptions'
/home/mneumann/savi/lib/clang/src/translation_unit.cr:23: error: undefined reference to 'clang_parseTranslationUnit2'
/home/mneumann/savi/lib/clang/src/index.cr:17: error: undefined reference to 'clang_disposeIndex'
/home/mneumann/savi/lib/clang/src/translation_unit.cr:41: error: undefined reference to 'clang_disposeTranslationUnit'
/home/mneumann/savi/lib/clang/src/translation_unit.cr:45: error: undefined reference to 'clang_getTranslationUnitCursor'

It seems all /usr/local/llvm14/lib/libclang*.a files have C++ name mangling. @jemc Is there some magic that you do when building llvm-static?

I get a step further with this:

clang14 -o build/savi-release -O3 -v \
        --target=x86_64-unknown-dragonfly \
        build/savi-release.o   \
        -L/usr/local/lib \
        -lm -lgc-threaded -levent -lpcre \
        -L/usr/local/llvm14/lib \
        -lLLVM-14 -lclang  \
        build/llvm_ext.bc \
        build/llvm_ext_for_savi.bc

using dynamic linking, but now it complains:

clang version 14.0.6
Target: x86_64-unknown-dragonfly
Thread model: posix
InstalledDir: /usr/local/llvm14/bin
 "/usr/local/llvm14/bin/clang-14" -cc1 -triple x86_64-unknown-dragonfly -emit-obj --mrelax-relocations -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name llvm_ext.bc -mrelocation-model static -mframe-pointer=all -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -mllvm -treat-scalable-fixed-error-as-warning -debugger-tuning=gdb -v -fcoverage-compilation-dir=/home/mneumann/savi -resource-dir /usr/local/llvm14/lib/clang/14.0.6 -O3 -fdebug-compilation-dir=/home/mneumann/savi -ferror-limit 19 -fgnuc-version=4.2.1 -fcolor-diagnostics -vectorize-loops -vectorize-slp -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/llvm_ext-cb6f9c.o -x ir build/llvm_ext.bc
clang -cc1 version 14.0.6 based upon LLVM 14.0.6 default target x86_64-portbld-dragonfly6.2
 "/usr/local/llvm14/bin/clang-14" -cc1 -triple x86_64-unknown-dragonfly -emit-obj --mrelax-relocations -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name llvm_ext_for_savi.bc -mrelocation-model static -mframe-pointer=all -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -mllvm -treat-scalable-fixed-error-as-warning -debugger-tuning=gdb -v -fcoverage-compilation-dir=/home/mneumann/savi -resource-dir /usr/local/llvm14/lib/clang/14.0.6 -O3 -fdebug-compilation-dir=/home/mneumann/savi -ferror-limit 19 -fgnuc-version=4.2.1 -fcolor-diagnostics -vectorize-loops -vectorize-slp -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/llvm_ext_for_savi-ee196e.o -x ir build/llvm_ext_for_savi.bc
clang -cc1 version 14.0.6 based upon LLVM 14.0.6 default target x86_64-portbld-dragonfly6.2
 "/usr/bin/ld" --eh-frame-hdr -dynamic-linker /usr/libexec/ld-elf.so.2 --hash-style=gnu --enable-new-dtags
 -o build/savi-release /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/gcc80/crtbegin.o -L/usr/local/lib -L/usr/local/llvm14/lib build/savi-release.o -lm -lgc-threaded -levent -lpcre -lLLVM-14 -lclang /tmp/llvm_ext-cb6f9c.o /tmp/llvm_ext_for_savi-ee196e.o -L/usr/lib/gcc80 -rpath /usr/lib/gcc80 -lc -lgcc --as-needed -lgcc_pic --no-as-needed /usr/lib/gcc80/crtend.o /usr/lib/crtn.o
/usr/libexec/binutils234/elf/ld.gold: internal error in read_header_prolog, at /usr/src/gnu/usr.bin/binutils234/block2/libgold/../../../../../contrib/binutils-2.34/gold/dwarf_reader.cc:1678
clang-14: error: linker command failed with exit code 1 (use -v to see invocation)

Am I using the wrong linker?

mneumann commented 1 year ago

I was successful, passing -fuse-ld and some missing libraries:

clang++14 -o build/savi-release -O3  -fuse-ld=lld -v \
        --target=x86_64-unknown-dragonfly \
        build/savi-release.o   \
        -L/usr/lib \
        -L/usr/local/lib \
        -L/usr/local/llvm14/lib \
        -lm -lgc-threaded -levent -lpcre -lz -pthread \
        -lLLVM-14 -lclang   \
        build/llvm_ext.bc \
        build/llvm_ext_for_savi.bc \
        `ls /usr/local/llvm14/lib/liblld*.a`
$ uname -a && ./build/savi-release --version
DragonFly s1.ntecs.de 6.2-RELEASE DragonFly v6.2.1.20.ge79614-RELEASE #15: Wed May  4 06:10:48 UTC 2022     root@s1.ntecs.de:/usr/obj/usr/src/sys/X86_64_GENERIC  x86_64
savi version: unknown
llvm version: 14.0.6

I somehow need to integrate that into the Makefile properly... and port over libsavi_runtime :)