diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3dc5c91d..69153095 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -410,8 +410,8 @@ jobs: # for cross build, cross-setup.sh takes care of the toolchain if: matrix.os == 'ubuntu-20.04' && matrix.arch == 'native' run: | - sudo ./cross/setup-focal-proposed.sh - sudo apt-get update && sudo apt-get install -y clang-13 lld-13 + sudo ./cross/setup-apt-llvm-org.sh + sudo apt-get update && sudo apt-get install -y clang-18 lld-18 sudo ./cross/setup-alternatives.sh - name: Fix sources.list (cross) @@ -426,7 +426,7 @@ jobs: ARCH: ${{matrix.arch}} EXTRA_CMAKE_OPTIONS: -G Ninja ${{env.extra_cmake_options}} -DTOYWASM_TARBALL_SUFFIX=-${{matrix.name}} run: | - sudo ./cross/setup-focal-proposed.sh + sudo ./cross/setup-apt-llvm-org.sh sudo -E ./cross/cross-setup.sh sudo ./cross/setup-alternatives.sh ./cross/cross-cmake-configure.sh diff --git a/cmake/ToywasmConfig.cmake b/cmake/ToywasmConfig.cmake index 93267b00..2589fd77 100644 --- a/cmake/ToywasmConfig.cmake +++ b/cmake/ToywasmConfig.cmake @@ -215,10 +215,7 @@ if (CMAKE_C_COMPILER_ID MATCHES "Clang") # lld doesn't seem to support s390 # ld.lld: error: unknown emulation: elf64_s390 # https://github.com/llvm/llvm-project/blob/93b7bdcda7072581ef3f5ceaae8c4f0d549a0845/lld/ELF/Driver.cpp#L142-L166 -# -# lld doesn't seem to support riscv relaxizations -# ld.lld: error: /usr/bin/../lib/gcc-cross/riscv64-linux-gnu/9/../../../../riscv64-linux-gnu/lib/crt1.o:(.text+0x0): relocation R_RISCV_ALIGN requires unimplemented linker relaxation; recompile with -mno-relax -if(NOT TRIPLET MATCHES "s390" AND NOT TRIPLET MATCHES "riscv64") +if(NOT TRIPLET MATCHES "s390") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=lld") else() set(USE_IPO OFF) @@ -226,12 +223,6 @@ endif() endif() endif() -# clang-13 on ubuntu/focal: -# ld.lld: error: lto.tmp: cannot link object files with different floating-point ABI -#if(TRIPLET MATCHES "riscv64") -#set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-plugin-opt=-target-abi=lp64d") -#endif() - if(TRIPLET MATCHES "i386") # x87 doesn't preserve sNaN as IEEE 754 and wasm expect. # unfortunately, clang doesn't have -mno-fp-ret-in-387. @@ -338,6 +329,20 @@ endif() if(CMAKE_C_COMPILER_ID STREQUAL GNU) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-builtin") endif() +# Clang 18's builtin ceil() etc seems to propagate sNaN as it is. +# (ubuntu/focal, riscv64, on qemu) +if(CMAKE_C_COMPILER_ID STREQUAL Clang) +if(TRIPLET MATCHES "riscv64") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-builtin-floor") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-builtin-floorf") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-builtin-ceil") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-builtin-ceilf") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-builtin-trunc") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-builtin-truncf") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-builtin-rint") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-builtin-rintf") +endif() +endif() set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -fomit-frame-pointer") #set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Xclang -fmerge-functions") diff --git a/cross/README.md b/cross/README.md index 108dacbf..7a6d6567 100644 --- a/cross/README.md +++ b/cross/README.md @@ -11,7 +11,7 @@ Our github CI jobs also use these scripts. Expected usage: ``` -./cross/setup-focal-proposed.sh +./cross/setup-apt-llvm-org.sh export ARCH=arm64 ./cross/cross-setup.sh ./cross/setup-alternatives.sh diff --git a/cross/cross-setup.sh b/cross/cross-setup.sh index f20d7bbc..a2b1092d 100755 --- a/cross/cross-setup.sh +++ b/cross/cross-setup.sh @@ -2,7 +2,7 @@ set -e -LLVM_VERSION=13 +LLVM_VERSION=18 dpkg --add-architecture ${ARCH} apt update diff --git a/cross/setup-alternatives.sh b/cross/setup-alternatives.sh index 2cddea0c..835eede6 100755 --- a/cross/setup-alternatives.sh +++ b/cross/setup-alternatives.sh @@ -2,7 +2,7 @@ set -e -LLVM_VERSION=${LLVM_VERSION:-13} +LLVM_VERSION=${LLVM_VERSION:-18} ALT_PRIO=100 COMMANDS=${1:-clang clang++ llvm-ar llvm-ranlib ld.lld lld} diff --git a/cross/setup-apt-llvm-org.sh b/cross/setup-apt-llvm-org.sh new file mode 100755 index 00000000..a30fcd16 --- /dev/null +++ b/cross/setup-apt-llvm-org.sh @@ -0,0 +1,11 @@ +#! /bin/sh + +# https://apt.llvm.org/ + +apt-get update +apt-get install -y curl gnupg1 +curl https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - + +cat < /etc/apt/sources.list.d/apt-llvm-org.list +deb http://apt.llvm.org/focal/ llvm-toolchain-focal-18 main +EOF diff --git a/lib/insn.c b/lib/insn.c index 23bbabfc..05943d1c 100644 --- a/lib/insn.c +++ b/lib/insn.c @@ -178,7 +178,7 @@ get_func_indirect(struct exec_context *ectx, uint32_t tableidx, /* * WASM float min/max follow IEEE 754-2019 minimum/maximum - * semantics: + * semantics, which are different from C fmin/fmax functions: * * - If either operand is a NaN (Note: can be an sNaN), returns a qNaN. * - -0.0 < +0.0