diff --git a/sysdeps/riscv/compiler-ext-avail.h b/sysdeps/riscv/compiler-ext-avail.h
new file mode 100644
index 0000000000..6b2d92e437
--- /dev/null
+++ b/sysdeps/riscv/compiler-ext-avail.h
@@ -0,0 +1,53 @@
+/* Copyright (C) 2024 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   This file is used to define whether extensions are available
+   in the compiler.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#ifndef _COMPILER_EXT_AVAIL_H
+#define _COMPILER_EXT_AVAIL_H 1
+
+/* Zba, Zbb, Zbc, and Zbs are available after gcc 12 or llvm 14 */
+
+#if (defined __GNUC__                                                         \
+     && (__GNUC__ > 12 || (__GNUC__ >= 12 && __GNUC_MINOR__ >= 1)))           \
+    || (defined __clang__ && __clang_major__ >= 14)
+#  define COMPILER_ZBA_AVAIL 1
+#  define COMPILER_ZBB_AVAIL 1
+#  define COMPILER_ZBC_AVAIL 1
+#  define COMPILER_ZBS_AVAIL 1
+#else
+#  define COMPILER_ZBA_AVAIL 0
+#  define COMPILER_ZBB_AVAIL 0
+#  define COMPILER_ZBC_AVAIL 0
+#  define COMPILER_ZBS_AVAIL 0
+#endif
+
+/* XTHeadBa, XTHeadBb, and XTHeadBs are available after gcc 13 or llvm 17 */
+#if (defined __GNUC__                                                         \
+     && (__GNUC__ > 13 || (__GNUC__ >= 13 && __GNUC_MINOR__ >= 1)))           \
+    || (defined __clang__ && __clang_major__ >= 17)
+#  define COMPILER_XTHEADBA_AVAIL 1
+#  define COMPILER_XTHEADBB_AVAIL 1
+#  define COMPILER_XTHEADBS_AVAIL 1
+#else
+#  define COMPILER_XTHEADBA_AVAIL 0
+#  define COMPILER_XTHEADBB_AVAIL 0
+#  define COMPILER_XTHEADBS_AVAIL 0
+#endif
+
+#endif /* compiler-ext-avail.h */
