From cd0c10ae6785e74f005db92ff0554df2454754e4 Mon Sep 17 00:00:00 2001 From: Maxim Reznik Date: Wed, 26 Jun 2024 14:45:11 +0300 Subject: [PATCH] Update to LLVM 16 and GCC 14 --- .copr/Makefile | 8 ++-- .copr/adawebpack.spec | 32 ++++++++++--- .github/workflows/build.yml | 28 +++++------ README.md | 51 +++++++++----------- patches/gnat-llvm.patch | 14 +++--- patches/llvm_wrapper2.patch | 89 +++++++++++++++++++++++++++++++++++ source/rtl/Makefile.target | 15 ++++-- source/rtl/s-finmas__wasm.adb | 14 ------ 8 files changed, 172 insertions(+), 79 deletions(-) create mode 100644 patches/llvm_wrapper2.patch diff --git a/.copr/Makefile b/.copr/Makefile index 78c5c01..6df7c6c 100644 --- a/.copr/Makefile +++ b/.copr/Makefile @@ -8,10 +8,10 @@ srpm: mkdir /tmp/.copr - cp -v `dirname $(spec)`/../patches/gnat-llvm.patch /tmp/.copr + cp -v `dirname $(spec)`/../patches/*.patch /tmp/.copr tar cavf /tmp/.copr/`grep ^Source0: $(spec)| sed -e 's/^.* //'` \ --exclude-vcs -C .. `basename $(realpath .)` - curl -L -o /tmp/.copr/gnat-llvm.zip https://github.com/AdaCore/gnat-llvm/archive/28c91e94c4227e6d9eabb2aeed4c0c12f6a4f3de.zip - curl -L -o /tmp/.copr/bb-runtimes.zip https://github.com/Fabien-Chouteau/bb-runtimes/archive/c1d089bd8880cec250266cf71d6a22cc74fdba79.zip - curl -L -o /tmp/.copr/gcc.zip https://github.com/gcc-mirror/gcc/archive/64d5610f44c995b88261bf83f53a200355cb530f.zip + curl -L -o /tmp/.copr/gnat-llvm.zip https://github.com/AdaCore/gnat-llvm/archive/66e36d929524972353600db5d604d0189cf0308f.zip + curl -L -o /tmp/.copr/bb-runtimes.zip https://github.com/Fabien-Chouteau/bb-runtimes/archive/e59080e0c4b49d12e00538595052dea2dceb5a6e.zip + curl -L -o /tmp/.copr/gcc.zip https://github.com/gcc-mirror/gcc/archive/cd0059a1976303638cea95f216de129334fc04d1.zip rpmbuild -bs $(spec) --define="_sourcedir /tmp/.copr" --define="_srcrpmdir $(outdir)" diff --git a/.copr/adawebpack.spec b/.copr/adawebpack.spec index 1adbeb7..97ac385 100644 --- a/.copr/adawebpack.spec +++ b/.copr/adawebpack.spec @@ -6,7 +6,7 @@ %define __os_install_post %{nil} Name: adawebpack -Version: 22.1.0 +Version: 24.0.0 Release: git%{?dist} Summary: Ada WASM Runtime and Bindings for Web API Group: Development/Libraries @@ -17,6 +17,7 @@ Source1: gnat-llvm.zip Source2: bb-runtimes.zip Source3: gcc.zip Patch0: gnat-llvm.patch +Patch1: llvm_wrapper2.patch BuildRequires: bsdtar BuildRequires: gcc-gnat BuildRequires: fedora-gnat-project-common >= 3 @@ -24,8 +25,8 @@ BuildRequires: gprbuild BuildRequires: gcc-c++ BuildRequires: libstdc++-static BuildRequires: lld -BuildRequires: llvm-devel >= 14 -BuildRequires: clang +BuildRequires: llvm16-devel +BuildRequires: clang16-devel BuildRequires: chrpath # gprbuild only available on these: @@ -35,22 +36,33 @@ ExclusiveArch: %GPRbuild_arches Ada WASM Runtime and Bindings for Web API %prep -%setup -T -b1 -a 0 -a 2 -n gnat-llvm-28c91e94c4227e6d9eabb2aeed4c0c12f6a4f3de/ +%setup -T -b1 -a 0 -a 2 -n gnat-llvm-66e36d929524972353600db5d604d0189cf0308f/ #export LANG=C.utf8 LANG=C.utf8 bsdtar -x -f %{S:3} gcc-*/gcc/ada mv -v gcc-*/gcc/ada llvm-interface/gnat_src mv %{name} llvm-interface/%{name}_src mv -v bb-runtimes-*/gnat_rts_sources/include/rts-sources llvm-interface/ ln -s %{name}_src/source/rtl/Makefile.target llvm-interface/ -%patch0 -p0 +%patch 0 -p0 +%patch 1 -p0 + %build +for J in /usr/bin/{llvm-config,opt,llvm-dis,llvm-ranlib}-16; do ln -v -s $J `basename $J -16`; done +export PATH=$PWD:$PATH + +ln -s /usr/lib64/llvm16/lib/libclang-cpp.so ./libclangBasic.so + +export LIBRARY_PATH=$PWD + make -C llvm-interface/ wasm -PATH=$PATH:`pwd`/llvm-interface/bin make -C llvm-interface/%{name}_src GPRBUILD_FLAGS=--db\ `pwd`/llvm-interface/%{name}_src/packages/Fedora +rm -v -f llvm-config opt llvm-dis llvm-ranlib +for J in /usr/bin/*-16; do ln -v -s $J `basename $J -16`; done +PATH=`pwd`/llvm-interface/bin:$PATH make -C llvm-interface/%{name}_src GPRBUILD_FLAGS=--db\ `pwd`/llvm-interface/%{name}_src/packages/Fedora %install cd llvm-interface -chrpath -d bin/* +find -D exec bin -size +100k -exec chrpath -d {} \; mkdir -p %{buildroot}/usr/share/gprconfig mkdir -p %{buildroot}/usr/lib/gnat mkdir -p %{buildroot}/usr/share/%{name} @@ -58,6 +70,7 @@ cp %{name}_src/packages/Fedora/llvm.xml %{buildroot}/usr/share/gprconfig/ cp %{name}_src/gnat/%{name}_config.gpr %{buildroot}/usr/lib/gnat/ cp -r bin lib %{buildroot}/usr cp -v %{name}_src/source/%{name}.mjs %{buildroot}/usr/share/%{name}/ +cp -v %{name}_src/utilities/update-alternatives-clang.sh %{buildroot}/usr/share/%{name}/ PATH=$PATH:`pwd`/bin gprconfig --batch -o /tmp/llvm.cgpr --db `pwd`/%{name}_src/packages/Fedora --target=llvm --config=ada,, PATH=$PATH:`pwd`/bin gprinstall --target=llvm --prefix=%{buildroot}/usr --project-subdir=%{buildroot}/usr/lib/gnat -P %{name}_src/gnat/%{name}.gpr -p --config=/tmp/llvm.cgpr @@ -68,6 +81,7 @@ PATH=$PATH:`pwd`/bin gprinstall --target=llvm --prefix=%{buildroot}/usr --projec %dir /usr/lib/rts-native %dir /usr/lib/gnat /usr/bin/llvm-* +/usr/bin/target.atp /usr/include/%{name}/*.ad[sb] /usr/lib/%{name}/*.{ali,o} /usr/lib/rts-native/adainclude/*.ad[sb] @@ -77,7 +91,11 @@ PATH=$PATH:`pwd`/bin gprinstall --target=llvm --prefix=%{buildroot}/usr --projec /usr/lib/gnat/manifests/%{name} /usr/share/gprconfig/llvm.xml /usr/share/%{name}/%{name}.mjs +/usr/share/%{name}/update-alternatives-clang.sh %changelog +* Thu Jun 27 2024 Maxim Reznik - 24.0.0-git +- Update to LLVM 16 and GCC 14 + * Fri Feb 21 2020 Maxim Reznik - 0.1.0-git - Initial package diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 793d3b1..21f2614 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,7 +11,7 @@ jobs: strategy: fail-fast: false matrix: # Build debug and production - os: [ubuntu-20.04] # , windows-latest] # there is no LLD 14 in msys2 anymore + os: [ubuntu-22.04] # , windows-latest] # there is no LLD 14 in msys2 anymore runs-on: ${{ matrix.os }} steps: - name: 'git config' @@ -23,7 +23,7 @@ jobs: if: ${{ runner.os != 'Windows' }} with: repository: AdaCore/gnat-llvm - ref: '28c91e94c4227e6d9eabb2aeed4c0c12f6a4f3de' + ref: '66e36d929524972353600db5d604d0189cf0308f' path: gnat-llvm - name: Get bb-runtimes @@ -32,7 +32,7 @@ jobs: with: repository: Fabien-Chouteau/bb-runtimes path: gnat-llvm/llvm-interface/bb-runtimes - ref: 'gnat-fsf-12' + ref: 'gnat-fsf-14' - name: Get gcc uses: actions/checkout@v2 @@ -40,7 +40,7 @@ jobs: with: repository: gcc-mirror/gcc path: gnat-llvm/llvm-interface/gcc - ref: '64d5610f44c995b88261bf83f53a200355cb530f' + ref: 'releases/gcc-14.1.0' - name: Get AdaWebPack uses: actions/checkout@v2 @@ -48,33 +48,33 @@ jobs: path: gnat-llvm/llvm-interface/adawebpack_src - name: Get GNAT toolchain with alire - uses: alire-project/setup-alire@v1 + uses: alire-project/setup-alire@v3 if: ${{ runner.os != 'Windows' }} with: - toolchain: gnat_native^12 gprbuild^22 - toolchain_dir: ./cached_gnat + toolchain: gnat_native^14 gprbuild - name: Fetch LLVM if: ${{ runner.os != 'Windows' }} run: | - URL=https://github.com/llvm/llvm-project/releases/download/llvmorg-14.0.0 - curl -L $URL/clang+llvm-14.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz \ + URL=https://github.com/llvm/llvm-project/releases/download/llvmorg-16.0.4 + curl -L $URL/clang+llvm-16.0.4-x86_64-linux-gnu-ubuntu-22.04.tar.xz \ | tar xJf - - name: Build (Linux) if: ${{ runner.os != 'Windows' }} run: | + alr toolchain --select gnat_native^14 gprbuild export PREFIX=$PWD/adawebpack export PATH=$PWD/gnat-llvm/llvm-interface/bin:$PATH - export PATH=`ls -d $PWD/cached_gnat/*/bin |tr '\n' ':'`$PATH - export PATH=$PWD/clang+llvm-14.0.0-x86_64-linux-gnu-ubuntu-18.04/bin:$PATH + export PATH=`ls -d $HOME/.local/share/alire/toolchains/*/bin |tr '\n' ':'`$PATH + export PATH=$PWD/clang+llvm-16.0.4-x86_64-linux-gnu-ubuntu-22.04/bin:$PATH echo PATH=$PATH pwd ls -l ls -l gnat-llvm/llvm-interface/ - cd gnat-llvm - patch -p0 < llvm-interface/adawebpack_src/patches/gnat-llvm.patch - cd llvm-interface + cd gnat-llvm/llvm-interface + patch -p1 < adawebpack_src/patches/gnat-llvm.patch + patch -p1 < adawebpack_src/patches/llvm_wrapper2.patch ln -sv gcc/gcc/ada gnat_src ln -sv adawebpack_src/source/rtl/Makefile.target ln -sv bb-runtimes/gnat_rts_sources/include/rts-sources diff --git a/README.md b/README.md index 71a78fb..9b70303 100644 --- a/README.md +++ b/README.md @@ -10,28 +10,28 @@ Prebuild packages are available on [Release page](https://github.com/godunko/ada You will also need `wasm-ld`, the Web asssembly linker. You will find this: * on Fedora Linux through the `lld` package; - * on Ubuntu through the `lld-15` package; + * on Ubuntu through the `lld-16` package; * on other Linux systems look for a similarly-named package. ## How to build - * Setup GNAT using [Alire](https://alire.ada.dev/) or GNAT Community 2021. + * Setup GNAT using [Alire](https://alire.ada.dev/). - * Clone [GNAT-LLVM](https://github.com/AdaCore/gnat-llvm). Latest known good revision of GNAT-LLVM compatible with GNAT FSF is `e000ea613704acc27238ec17ce020251427f9e1d`. + * Clone [GNAT-LLVM](https://github.com/AdaCore/gnat-llvm). Latest known good revision of GNAT-LLVM compatible with GNAT FSF is `66e36d929524972353600db5d604d0189cf0308f`. ``` git clone https://github.com/AdaCore/gnat-llvm - git -C gnat-llvm checkout e000ea613704acc27238ec17ce020251427f9e1d + git -C gnat-llvm checkout 66e36d929524972353600db5d604d0189cf0308f ``` - * Clone [bb-runtimes](https://github.com/Fabien-Chouteau/bb-runtimes). Use `gnat-fsf-12` branch. + * Clone [bb-runtimes](https://github.com/Fabien-Chouteau/bb-runtimes). Use `gnat-fsf-14` branch. ``` - git clone -b gnat-fsf-12 https://github.com/Fabien-Chouteau/bb-runtimes gnat-llvm/llvm-interface/bb-runtimes + git clone -b gnat-fsf-14 https://github.com/Fabien-Chouteau/bb-runtimes gnat-llvm/llvm-interface/bb-runtimes ``` - * Clone [GCC](https://github.com/gcc-mirror/gcc) sources. Use, for instance, `e000ea613704acc27238ec17ce020251427f9e1d` commit. + * Clone [GCC](https://github.com/gcc-mirror/gcc) sources. Use, for instance, `releases/gcc-14.1.0` commit. ``` - git clone --single-branch --shallow-since=13-11-2022 https://github.com/gcc-mirror/gcc gnat-llvm/llvm-interface/gcc - git -C gnat-llvm/llvm-interface/gcc checkout e000ea613704acc27238ec17ce020251427f9e1d + git clone --single-branch --branch=releases/gcc-14 --shallow-since=01-04-2024 https://github.com/gcc-mirror/gcc gnat-llvm/llvm-interface/gcc + git -C gnat-llvm/llvm-interface/gcc checkout releases/gcc-14.1.0 ``` * Setup GNAT-LLVM development environment, see details in @@ -43,14 +43,14 @@ You will also need `wasm-ld`, the Web asssembly linker. You will find this: cmake ... -DLLVM_ENABLE_PROJECTS='...;clang;lld' -DLLVM_TARGETS_TO_BUILD="...;WebAssembly" ``` - On Ubuntu it is possible to install prebuild LLVM/CLang packages (use LLVM/CLang 15). However, + On Ubuntu it is possible to install prebuild LLVM/CLang packages (use LLVM/CLang 16). However, alternatives need to be updated using the provided script: ``` - sudo utilities/update-alternatives-clang.sh 15 100 + sudo utilities/update-alternatives-clang.sh 16 100 ``` - Or install a [LLVM 15 binary release](https://github.com/llvm/llvm-project/releases) (`llvm-15`, `lld-15` and `clang-15` are required). + Or install a [LLVM 16 binary release](https://github.com/llvm/llvm-project/releases) (`llvm-16`, `lld-16` and `clang-16` are required). * Checkout AdaWebPack repository into `gnat-llvm/llvm-interface` as `adawebpack_src` and create link for Makefile.target. @@ -78,8 +78,9 @@ You will also need `wasm-ld`, the Web asssembly linker. You will find this: * Apply patch to GNAT-LLVM repository ``` - cd gnat-llvm - patch -p0 < llvm-interface/adawebpack_src/patches/gnat-llvm.patch + cd gnat-llvm/llvm-interface + patch -p1 < adawebpack_src/patches/gnat-llvm.patch + patch -p1 < adawebpack_src/patches/llvm_wrapper2.patch cd - ``` @@ -114,27 +115,19 @@ It could be handy to use docker. * Build a container image (make sure to replace `curl` argument with latest RPM URL) ``` docker build --tag wgprbuild - < ++#include ++ ++using namespace llvm; ++ ++static TargetMachine *unwrap(LLVMTargetMachineRef P) { ++ return reinterpret_cast(P); ++} ++static Target *unwrap(LLVMTargetRef P) { ++ return reinterpret_cast(P); ++} ++static LLVMTargetMachineRef wrap(const TargetMachine *P) { ++ return reinterpret_cast(const_cast(P)); ++} ++static LLVMTargetRef wrap(const Target * P) { ++ return reinterpret_cast(const_cast(P)); ++} ++ ++extern "C" ++LLVMTargetMachineRef LLVMCreateTargetMachineWithABI(LLVMTargetRef T, ++ const char *Triple, const char *CPU, const char *Features, ++ const char *ABI, LLVMCodeGenOptLevel Level, LLVMRelocMode Reloc, ++ LLVMCodeModel CodeModel) { ++ std::optional RM; ++ switch (Reloc){ ++ case LLVMRelocStatic: ++ RM = Reloc::Static; ++ break; ++ case LLVMRelocPIC: ++ RM = Reloc::PIC_; ++ break; ++ case LLVMRelocDynamicNoPic: ++ RM = Reloc::DynamicNoPIC; ++ break; ++ case LLVMRelocROPI: ++ RM = Reloc::ROPI; ++ break; ++ case LLVMRelocRWPI: ++ RM = Reloc::RWPI; ++ break; ++ case LLVMRelocROPI_RWPI: ++ RM = Reloc::ROPI_RWPI; ++ break; ++ default: ++ break; ++ } ++ ++ bool JIT; ++ std::optional CM = unwrap(CodeModel, JIT); ++ ++ CodeGenOpt::Level OL; ++ switch (Level) { ++ case LLVMCodeGenLevelNone: ++ OL = CodeGenOpt::None; ++ break; ++ case LLVMCodeGenLevelLess: ++ OL = CodeGenOpt::Less; ++ break; ++ case LLVMCodeGenLevelAggressive: ++ OL = CodeGenOpt::Aggressive; ++ break; ++ default: ++ OL = CodeGenOpt::Default; ++ break; ++ } ++ ++ TargetOptions opt; ++ opt.MCOptions.ABIName = ABI; ++ return wrap(unwrap(T)->createTargetMachine(Triple, CPU, Features, opt, RM, CM, ++ OL, JIT)); ++} ++ diff --git a/source/rtl/Makefile.target b/source/rtl/Makefile.target index 02ac4ce..a0d1dfe 100644 --- a/source/rtl/Makefile.target +++ b/source/rtl/Makefile.target @@ -134,8 +134,13 @@ s-valuns.adb \ s-valuns.ads \ s-valuti.adb \ s-valuti.ads \ +s-valspe.adb \ +s-valspe.ads \ s-vauspe.adb \ s-vauspe.ads \ +s-vs_uns.ads \ +s-vs_llu.ads \ +s-vs_int.ads \ s-wchcnv.ads \ s-wchstw.ads \ s-wchwts.adb \ @@ -270,7 +275,7 @@ wasm: build cp -p $(GNAT_SRC)/libgnat/$$f $(WASMINCLUDE); \ done cp -p $(AWP_SRC)/rtl/a-elchha__wasm.adb $(WASMINCLUDE)/a-elchha.adb - cp -p $(RTS_SRC)/light/a-elchha.ads $(WASMINCLUDE)/ + cp -p $(RTS_SRC)/light/exceptions/a-elchha.ads $(WASMINCLUDE)/ cp -p $(AWP_SRC)/rtl/a-except.ad[sb] $(WASMINCLUDE)/ # cp -p $(GNAT_SRC)/hie/i-c__hie.ads $(WASMINCLUDE)/i-c.ads cp -p $(RTS_SRC)/math/a-ngelfu.ad[sb] $(WASMINCLUDE)/ @@ -293,11 +298,13 @@ wasm: build cp -p $(RTS_SRC)/math/hardsp/s-lisisq.adb $(WASMINCLUDE)/ cp -p $(RTS_SRC)/math/s-lisisq.ads $(WASMINCLUDE)/ cp -p $(RTS_SRC)/mem/s-memcom.ad[sb] $(WASMINCLUDE)/ - cp -p $(RTS_SRC)/mem/s-memcop.ad[sb] $(WASMINCLUDE)/ - cp -p $(RTS_SRC)/mem/s-memmov.ad[sb] $(WASMINCLUDE)/ + cp -p $(RTS_SRC)/mem/s-memcop.ads $(WASMINCLUDE)/ + cp -p $(RTS_SRC)/mem/no-cheri/s-memcop.adb $(WASMINCLUDE)/ + cp -p $(RTS_SRC)/mem/s-memmov.ads $(WASMINCLUDE)/ + cp -p $(RTS_SRC)/mem/no-cheri/s-memmov.adb $(WASMINCLUDE)/ cp -p $(AWP_SRC)/rtl/s-memory__wasm.adb $(WASMINCLUDE)/s-memory.adb cp -p $(RTS_SRC)/mem/s-memset.ad[sb] $(WASMINCLUDE)/ - cp -p $(RTS_SRC)/mem/s-memtyp.ads $(WASMINCLUDE)/ + cp -p $(RTS_SRC)/mem/no-cheri/s-memtyp.ads $(WASMINCLUDE)/ cp -p $(AWP_SRC)/rtl/s-parame.ads $(WASMINCLUDE)/ cp -p $(AWP_SRC)/rtl/s-soflin.adb $(WASMINCLUDE)/ cp -p $(AWP_SRC)/rtl/s-soflin.ads $(WASMINCLUDE)/ diff --git a/source/rtl/s-finmas__wasm.adb b/source/rtl/s-finmas__wasm.adb index a9c6757..768a2b5 100644 --- a/source/rtl/s-finmas__wasm.adb +++ b/source/rtl/s-finmas__wasm.adb @@ -74,20 +74,6 @@ package body System.Finalization_Masters is return System.Storage_Elements."+" (Addr, Offset); end Add_Offset_To_Address; - ------------ - -- Attach -- - ------------ - - procedure Attach (N : not null FM_Node_Ptr; L : not null FM_Node_Ptr) is - begin - Lock_Task.all; - Attach_Unprotected (N, L); - Unlock_Task.all; - - -- Note: No need to unlock in case of an exception because the above - -- code can never raise one. - end Attach; - ------------------------ -- Attach_Unprotected -- ------------------------