RFR: 8341880: RISC-V: riscv_vector.h native build fails with gcc13 after JDK-8320500
Hamlin Li
mli at openjdk.org
Thu Oct 10 10:08:11 UTC 2024
On Thu, 10 Oct 2024 07:37:43 GMT, SendaoYan <syan at openjdk.org> wrote:
> Hi all,
> The file `src/jdk.incubator.vector/linux/native/libsleef/lib/vector_math_rvv.c` introduced by [JDK-8341880](https://bugs.openjdk.org/browse/JDK-8341880) native build fails by fedora OS shipped gcc13.
> Gcc13 doesn't have `__riscv_v_intrinsic` macro by default, and do have `__riscv_v_intrinsic` macro with option: `-march=rv64gcv`. So I think the CFLAGS should not set `-march=rv64gcv`, because gcc13 doesn't have `riscv_vector.h`.
>
> 
>
>
> gcc version infomation:
>
> /usr/bin/gcc -v
> Using built-in specs.
> COLLECT_GCC=/usr/bin/gcc
> COLLECT_LTO_WRAPPER=/usr/libexec/gcc/riscv64-redhat-linux/13/lto-wrapper
> Target: riscv64-redhat-linux
> Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,objc,obj-c++,ada,go,d,m2,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --enable-libstdcxx-backtrace --with-libstdcxx-zoneinfo=/usr/share/zoneinfo --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl=/builddir/build/BUILD/gcc-13.2.1-20230728/obj-riscv64-redhat-linux/isl-install --enable-gnu-indirect-function --with-arch=rv64gc --with-abi=lp64d --with-multilib-list=lp64d --build=riscv64-redhat-linux --with-build-config=bootstrap-lto --enable-link-serialization=1
> Thread model: posix
> Supported LTO compression algorithms: zlib zstd
> gcc version 13.2.1 20230728 (Red Hat 13.2.1-1) (GCC)
>
>
> Additonal testing:
>
> - [x] riscv64 native release debug-level build with gcc13
> - [ ] riscv64 native fastdebug debug-level build with gcc13
> - [ ] riscv64 native release debug-level build with gcc14
> - [ ] riscv64 native fastdebug debug-level build with gcc14
Can you try something like below?
make/modules/jdk.incubator.vector/Lib.gmk line 53:
> 51: DISABLED_WARNINGS_gcc := unused-function sign-compare tautological-compare ignored-qualifiers, \
> 52: DISABLED_WARNINGS_clang := unused-function sign-compare tautological-compare ignored-qualifiers, \
> 53: CFLAGS := -march=rv64gcv, \
diff --git a/make/autoconf/flags-cflags.m4 b/make/autoconf/flags-cflags.m4
index 992a0282c04..2c54b356c5d 100644
--- a/make/autoconf/flags-cflags.m4
+++ b/make/autoconf/flags-cflags.m4
@@ -912,6 +912,37 @@ AC_DEFUN([FLAGS_SETUP_CFLAGS_CPU_DEP],
IF_FALSE: [$2FDLIBM_CFLAGS=""])
fi
AC_SUBST($2FDLIBM_CFLAGS)
+
+ # Check that the compiler support -march=rv64gcv and riscv_vector.h
+ if test "x${OPENJDK_TARGET_CPU}" = "xriscv64"; then
+ if test "x$TOOLCHAIN_TYPE" = xgcc || test "x$TOOLCHAIN_TYPE" = xclang; then
+ AC_LANG_PUSH(C)
+ OLD_CFLAGS="$CFLAGS"
+ CFLAGS="$CFLAGS -march=rv64gcv"
+ AC_MSG_CHECKING([is rvv intrinsic supported])
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <riscv_vector.h>],
+ [
+ const char *src = (const char*) malloc(1024);
+ char *dst = (char*) malloc(1024);
+ size_t vl = __riscv_vsetvl_e8m8(16);
+ vuint8m8_t vec_src = __riscv_vle8_v_u8m8(src, vl);
+ __riscv_vse8_v_u8m8(dst, vec_src, vl);
+ return strlen(dst);
+ ])],
+ [
+ AC_MSG_RESULT([yes])
+ $2RVV_INTRINSICS_CFLAGS="-march=rv64gcv"
+ ],
+ [
+ AC_MSG_RESULT([no])
+ $2RVV_INTRINSICS_CFLAGS=""
+ ]
+ )
+ CFLAGS="$OLD_CFLAGS"
+ AC_LANG_POP(C)
+ fi
+ fi
+ AC_SUBST($2RVV_INTRINSICS_CFLAGS)
])
# FLAGS_SETUP_GCC6_COMPILER_FLAGS([PREFIX])
diff --git a/make/autoconf/spec.gmk.template b/make/autoconf/spec.gmk.template
index 20b1d00aa89..a95f5cb5793 100644
--- a/make/autoconf/spec.gmk.template
+++ b/make/autoconf/spec.gmk.template
@@ -827,6 +827,9 @@ OS_VERSION_MAJOR := @OS_VERSION_MAJOR@
OS_VERSION_MINOR := @OS_VERSION_MINOR@
OS_VERSION_MICRO := @OS_VERSION_MICRO@
+# Riscv: RVV intrinsics flags
+RVV_INTRINSICS_CFLAGS := @RVV_INTRINSICS_CFLAGS@
+
# Images directory definitions
JDK_IMAGE_SUBDIR := jdk
JRE_IMAGE_SUBDIR := jre
diff --git a/make/modules/jdk.incubator.vector/Lib.gmk b/make/modules/jdk.incubator.vector/Lib.gmk
index c6c6103a301..6b689a32a77 100644
--- a/make/modules/jdk.incubator.vector/Lib.gmk
+++ b/make/modules/jdk.incubator.vector/Lib.gmk
@@ -47,6 +47,7 @@ ifeq ($(call isTargetOs, linux)+$(call isTargetCpu, riscv64)+$(INCLUDE_COMPILER2
DISABLED_WARNINGS_gcc := unused-function sign-compare tautological-compare ignored-qualifiers, \
DISABLED_WARNINGS_clang := unused-function sign-compare tautological-compare ignored-qualifiers, \
CFLAGS := $(CFLAGS_JDKLIB) -march=rv64gcv, \
+ vector_math_rvv.c_CFLAGS := $(RVV_INTRINSICS_CFLAGS), \
LDFLAGS := $(LDFLAGS_JDKLIB) \
$(call SET_SHARED_LIBRARY_ORIGIN), \
LIBS := $(JDKLIB_LIBS) \
-------------
PR Review: https://git.openjdk.org/jdk/pull/21442#pullrequestreview-2359725482
PR Review Comment: https://git.openjdk.org/jdk/pull/21442#discussion_r1795107665
More information about the build-dev
mailing list