]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
RISC-V: [gprofng] Allow building gprofng without asm/hwprobe.h
authorWANG Xuerui <git@xen0n.name>
Mon, 16 Jun 2025 08:16:55 +0000 (16:16 +0800)
committerVladimir Mezentsev <vladimir.mezentsev@oracle.com>
Mon, 30 Jun 2025 16:32:05 +0000 (09:32 -0700)
The code is actually able to gracefully fallback if the syscall number
of riscv_hwprobe is not available at build time, but it still depended
on the <asm/hwprobe.h> header unconditionally. In certain environments
such as one of crosstool-NG's Canadian Cross build step (binutils for
host), or one with very outdated kernel headers, the header will not be
present, causing the build to fail.

While the relevant projects/environments should be fixed nevertheless,
a configure-time check for <asm/hwprobe.h> is helpful for fixing gprofng
builds with released versions of ct-ng etc.

Signed-off-by: WANG Xuerui <git@xen0n.name>
gprofng/common/config.h.in
gprofng/common/cpuid.c
gprofng/configure
gprofng/configure.ac

index aabb043957af258beedf7752d958ef5552d0ae4b..5f2c1278c958b7e83fd88a573737d12b70201f4a 100644 (file)
@@ -9,6 +9,9 @@
 /* Enable java profiling */
 #undef GPROFNG_JAVA_PROFILING
 
+/* Define to 1 if you have the <asm/hwprobe.h> header file. */
+#undef HAVE_ASM_HWPROBE_H
+
 /* Define to 1 if you have the `clock_gettime' function. */
 #undef HAVE_CLOCK_GETTIME
 
index e40404c645a5f97e62cc37d8f964879f05da3ea9..f9f904628395af648c48932235ceacf2a197901d 100644 (file)
@@ -48,8 +48,10 @@ __get_cpuid (unsigned int op ATTRIBUTE_UNUSED, unsigned int *eax,
 #include <sched.h>
 #include <sys/syscall.h>
 #include <unistd.h>
+#ifdef HAVE_ASM_HWPROBE_H
 #include <asm/hwprobe.h>
 #endif
+#endif
 
 /*
  * Various routines to handle identification
@@ -188,7 +190,7 @@ get_cpuid_info ()
       break;
     }
 #elif defined(__riscv)
-  #ifndef __riscv_hwprobe
+  #if !defined(__riscv_hwprobe) || !defined(HAVE_ASM_HWPROBE_H)
          cpi->cpi_vendor = 0;
          cpi->cpi_family = 0;
          cpi->cpi_model = 0;
@@ -208,7 +210,7 @@ get_cpuid_info ()
        cpi->cpi_vendor = res.value;
        cpi->cpi_family = 0;
        cpi->cpi_model = 0;
-       #endif
+  #endif
 #endif
   return cpi;
 }
index 2edfff107dd5334ed35007febd28ba5f25bde207..2f4e18c47f657a41cc8915daa62683b3efa1ef8c 100755 (executable)
 done
 
 
+# For riscv builds inside incomplete environments such as during intermediate
+# steps of cross toolchain building, or with outdated Linux headers.
+for ac_header in asm/hwprobe.h
+do :
+  ac_fn_c_check_header_mongrel "$LINENO" "asm/hwprobe.h" "ac_cv_header_asm_hwprobe_h" "$ac_includes_default"
+if test "x$ac_cv_header_asm_hwprobe_h" = xyes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_ASM_HWPROBE_H 1
+_ACEOF
+
+fi
+
+done
+
+
 clock_gettime_link=
 # At least for glibc, clock_gettime is in librt.  But don't
 # pull that in if it still doesn't give us the function we want.  This
index 1f473b9b5833b859b940e1dfc0130726a16b0236..deb3ed586daf88d0ea64410e039542fce2569617 100644 (file)
@@ -245,6 +245,10 @@ AC_SUBST(GPROFNG_CPPFLAGS, [${gprofng_cppflags}])
 AC_CHECK_DECLS([basename])
 AC_CHECK_FUNCS(clock_gettime strsignal)
 
+# For riscv builds inside incomplete environments such as during intermediate
+# steps of cross toolchain building, or with outdated Linux headers.
+AC_CHECK_HEADERS(asm/hwprobe.h)
+
 clock_gettime_link=
 # At least for glibc, clock_gettime is in librt.  But don't
 # pull that in if it still doesn't give us the function we want.  This