AdaCore / gnat-llvm

LLVM based GNAT compiler
179 stars 18 forks source link

Build failure on Ubuntu 24.04 LTS #43

Closed rod-chapman closed 2 months ago

rod-chapman commented 2 months ago

Dear AdaCore, I am trying to build GNAT-LLVM on an Intel-based AWS EC2 instance (a c7i.4xlarge instance type), running Ubuntu 24.04 LTS

I have the "gnat" and "gprbuild" packages installed from "apt", plus clang-16, llvm-16, libclang-dev-16 packages. I also found I had to add the "g++-13" package to get the required header files for C++

Anyway - the build fails now with

~/gnat/gnat-llvm$ make -j1
make -C llvm-interface build gnatlib-automated
make[1]: Entering directory '/home/ubuntu/gnat/gnat-llvm/llvm-interface'
mkdir -p obj obj-tools/libgnat bin gnat_src/vast
for f in `cd /home/ubuntu/gnat/gnat-llvm/llvm-interface/gnat_src; ls gen_il*.ad? xutil.ad? *-tmpl xoscons.adb xsnamest.adb`; \
do \
  cp -p /home/ubuntu/gnat/gnat-llvm/llvm-interface/gnat_src/$f obj-tools; \
done
cd obj-tools && gnatmake -q -j0 xoscons xsnamest && ./xsnamest && \
mv -f snames.ns ../obj/snames.ads && mv -f snames.nb ../obj/snames.adb && \
gnatmake -g -q -j0 gen_il-main.adb -I../obj -Ilibgnat && ./gen_il-main && \
mv -f nmake.adb nmake.ads seinfo.ads sinfo-nodes.ads sinfo-nodes.adb einfo-entities.ads einfo-entities.adb ../obj
for f in ../link.c s-pehage.adb s-pehage.ads s-rident.ads s-utf_32.adb s-utf_32.ads gnat.ads g-byorma.adb g-casuti.adb g-casuti.ads g-comlin.adb g-comlin.ads g-ctrl_c.adb g-ctrl_c.ads g-dirope.adb g-dynhta.adb g-dynhta.ads g-graphs.adb g-graphs.ads g-hesora.adb g-htable.adb g-io.adb g-io_aux.adb g-io_aux.ads g-lists.adb g-lists.ads g-os_lib.adb g-os_lib.ads g-regexp.ads g-sets.adb g-sets.ads g-spchge.adb g-speche.adb g-string.ads g-u3spch.adb; do \
  ln -sf /home/ubuntu/gnat/gnat-llvm/llvm-interface/gnat_src/libgnat/$f obj; \
done
./check_for_LLVM_aliasing_bug.sh
using LLVM with the aliasing bug, will pessimize slightly the optimized code
gprbuild -v -n -Pgnat_llvm -j0 \
  -largs -L/usr/lib/llvm-16/lib  -lLLVM-16 -rdynamic -cargs:c++ -I/usr/lib/llvm-16/include -std=c++17   -fno-exceptions -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS  
Changing to object directory of "Gnat_LLVM": "/home/ubuntu/gnat/gnat-llvm/llvm-interface/obj/"
/usr/bin/g++-13 gnat1drv.o /tmp/GPR.15256/GNAT-TEMP-000003.TMP libgnat_llvm.a -static-libstdc++ -lclangBasic -L/usr/lib/llvm-16/lib -lLLVM-16 -rdynamic -L/home/ubuntu/gnat/gnat-llvm/llvm-interface/obj/ -L/home/ubuntu/gnat/gnat-llvm/llvm-interface/obj/ -L/usr/lib/gcc/x86_64-linux-gnu/13/adalib/ -lgnat-13 -ldl -Wl,-rpath-link,/usr/lib/gcc/x86_64-linux-gnu/13//adalib -static-libgcc -no-pie -Wl,-z,origin,-rpath,/usr/lib/llvm-16/lib:$ORIGIN/..//obj:/usr/lib/gcc/x86_64-linux-gnu/13/adalib -o /home/ubuntu/gnat/gnat-llvm/llvm-interface/bin//llvm-gnat1
/usr/bin/g++-13 gcc_wrapper.o b__gcc_wrapper.o /home/ubuntu/gnat/gnat-llvm/llvm-interface/obj/gnat.o /home/ubuntu/gnat/gnat-llvm/llvm-interface/obj/g-os_lib.o /home/ubuntu/gnat/gnat-llvm/llvm-interface/obj/gnatvsn.o /home/ubuntu/gnat/gnat-llvm/llvm-interface/obj/llvm.o /home/ubuntu/gnat/gnat-llvm/llvm-interface/obj/llvm-types.o /home/ubuntu/gnat/gnat-llvm/llvm-interface/obj/llvm-target.o /home/ubuntu/gnat/gnat-llvm/llvm-interface/obj/llvm-target_machine.o libgnat_llvm.a -static-libstdc++ -lclangBasic -L/usr/lib/llvm-16/lib -lLLVM-16 -rdynamic -L/home/ubuntu/gnat/gnat-llvm/llvm-interface/obj/ -L/home/ubuntu/gnat/gnat-llvm/llvm-interface/obj/ -L/usr/lib/gcc/x86_64-linux-gnu/13/adalib/ -lgnat-13 -ldl -Wl,-rpath-link,/usr/lib/gcc/x86_64-linux-gnu/13//adalib -static-libgcc -no-pie -Wl,-z,origin,-rpath,/usr/lib/llvm-16/lib:$ORIGIN/..//obj:/usr/lib/gcc/x86_64-linux-gnu/13/adalib -o /home/ubuntu/gnat/gnat-llvm/llvm-interface/bin//llvm-gcc
/usr/bin/ld: /home/ubuntu/gnat/gnat-llvm/llvm-interface/obj/llvm-target_machine.o: in function `llvm__target_machine__create_target_machine_with_abi':
/home/ubuntu/gnat/gnat-llvm/llvm/adainclude/llvm-target_machine.adb:219:(.text+0x16b7): undefined reference to `LLVMCreateTargetMachineWithABI'
collect2: error: ld returned 1 exit status
/usr/bin/ld: /home/ubuntu/gnat/gnat-llvm/llvm-interface/obj/llvm-target_machine.o: in function `llvm__target_machine__create_target_machine_with_abi':
/home/ubuntu/gnat/gnat-llvm/llvm/adainclude/llvm-target_machine.adb:219:(.text+0x16b7): undefined reference to `LLVMCreateTargetMachineWithABI'
collect2: error: ld returned 1 exit status
   link of gcc_wrapper.adb failed
   link of gnat1drv.adb failed
gprbuild: *** link phase failed
make[1]: *** [Makefile:87: build] Error 4
make[1]: Leaving directory '/home/ubuntu/gnat/gnat-llvm/llvm-interface'
make: *** [Makefile:2: all] Error 2

Any idea where I went wrong? Thanks, Rod

rod-chapman commented 2 months ago

i can see that my /usr/lib/llvm-16/lib/libLLVM-16.so.1 does contain LLVMCreateTargetMachine but NOT LLVMCreateTargetMachineWithABI.

The latter appears to come from a patch that you apply to the LLVM sources. Do I need to rebuild libLLVM from source after the patch has been applied? That does not appear in the README.md file as far as I can see... Thanks, Rod

Lucretia commented 2 months ago

Might be part of llvm-18, but the only reference I could find was this.

Why are they using patches that are not in the main releases?

ArnaudCharlet commented 2 months ago

You currently indeed need to rebuild LLVM with the patch llvm/patches/LLVMCreateTargetMachineWithABI.diff, sorry about the extra work! We have contributed this patch which is needed on some targets, and whenever we upgrade GNAT LLVM to a more recent version of LLVM, this will no longer be needed.

rod-chapman commented 2 months ago

So I need to get the LLVM-16 sources, apply the patch(es), then re-build from source? Got any instructions?

ArnaudCharlet commented 2 months ago

So I need to get the LLVM-16 sources, apply the patch(es), then re-build from source? Got any instructions?

Right.

You can use the Makefile under the llvm directory which provides support for building LLVM from scratch. You still need to apply the patch by hand, so you need to basically do:

cd llvm make setup <apply patches/LLVMCreateTargetMachineWithABI.diff under llvm-project-16.0.6.src> make llvm

rod-chapman commented 2 months ago

Aha! I had missed the "make setup" step.

Do I need to apply all the patches, or just that one?

ArnaudCharlet commented 2 months ago

Aha! I had missed the "make setup" step.

Do I need to apply all the patches, or just that one?

The other patches aren't critical, but can also be applied.

Arno