Skip to contentSkip to conversation

util/util/cpuinfo-riscv.c: fix riscv64 build on musl libc

PATCH Applied Milan P. Stanić 4 participants 5 messages Sep 5, 2024 – Sep 6, 2024 RISC-V

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 util/util/cpuinfo-riscv.c: fix riscv64 build on musl libc

build fails on musl libc (alpine linux) with this error:

../util/cpuinfo-riscv.c: In function 'cpuinfo_init':
../util/cpuinfo-riscv.c:63:21: error: '__NR_riscv_hwprobe' undeclared (first use in this function); did you mean 'riscv_hwprobe'?

   63 |         if (syscall(__NR_riscv_hwprobe, &pair, 1, 0, NULL, 0) == 0
      |                     ^~~~~~~~~~~~~~~~~~
      |                     riscv_hwprobe

../util/cpuinfo-riscv.c:63:21: note: each undeclared identifier is reported only once for each function it appears in
ninja: subcommand failed

add '#include "asm/unistd.h"' to util/cpuinfo-riscv.c fixes build

---
 util/cpuinfo-riscv.c | 1 +
 1 file changed, 1 insertion(+)
util/cpuinfo-riscv.c +1 -0
index 497ce12680..8cacc67645 100644
@@ -9,6 +9,7 @@
 #ifdef CONFIG_ASM_HWPROBE_H
 #include <asm/hwprobe.h>
 #include <sys/syscall.h>
+#include <asm/unistd.h>
 #endif
 
 unsigned cpuinfo;
Signature · 1 line
2.46.0
#1 lore raw
Quoted 22 lines · Milan P. Stanić

build fails on musl libc (alpine linux) with this error:

../util/cpuinfo-riscv.c: In function 'cpuinfo_init':
../util/cpuinfo-riscv.c:63:21: error: '__NR_riscv_hwprobe' undeclared (first use in this function); did you mean 'riscv_hwprobe'?

    63 |         if (syscall(__NR_riscv_hwprobe, &pair, 1, 0, NULL, 0) == 0
       |                     ^~~~~~~~~~~~~~~~~~
       |                     riscv_hwprobe

../util/cpuinfo-riscv.c:63:21: note: each undeclared identifier is reported only once for each function it appears in
ninja: subcommand failed

add '#include "asm/unistd.h"' to util/cpuinfo-riscv.c fixes build

---
  util/cpuinfo-riscv.c | 1 +
  1 file changed, 1 insertion(+)
util/cpuinfo-riscv.c +0 -0
index 497ce12680..8cacc67645 100644

util/cpuinfo-riscv.c line 12

Quoted 4 lines
util/cpuinfo-riscv.c +1 -0
@@ -9,6 +9,7 @@
  #ifdef CONFIG_ASM_HWPROBE_H
  #include <asm/hwprobe.h>
  #include <sys/syscall.h>
+#include <asm/unistd.h>

I suppose this is ok, but...

For some reason musl processes asm/unistd.h at build-time to produce <bits/syscall.h>, which is included by <sys/syscall.h>. This will be "fixed" the next time musl is rebuilt against current kernel headers.

r~

#2 lore raw
Quoted 31 lines · Richard Henderson
Quoted 22 lines · Milan P. Stanić

build fails on musl libc (alpine linux) with this error:

../util/cpuinfo-riscv.c: In function 'cpuinfo_init':
../util/cpuinfo-riscv.c:63:21: error: '__NR_riscv_hwprobe' undeclared (first use in this function); did you mean 'riscv_hwprobe'?

    63 |         if (syscall(__NR_riscv_hwprobe, &pair, 1, 0, NULL, 0) == 0
       |                     ^~~~~~~~~~~~~~~~~~
       |                     riscv_hwprobe

../util/cpuinfo-riscv.c:63:21: note: each undeclared identifier is reported only once for each function it appears in
ninja: subcommand failed

add '#include "asm/unistd.h"' to util/cpuinfo-riscv.c fixes build

---
  util/cpuinfo-riscv.c | 1 +
  1 file changed, 1 insertion(+)
util/cpuinfo-riscv.c +0 -0
index 497ce12680..8cacc67645 100644

util/cpuinfo-riscv.c line 12

Quoted 4 lines
util/cpuinfo-riscv.c +1 -0
@@ -9,6 +9,7 @@
  #ifdef CONFIG_ASM_HWPROBE_H
  #include <asm/hwprobe.h>
  #include <sys/syscall.h>
+#include <asm/unistd.h>

I suppose this is ok, but...

Quoted 3 lines

For some reason musl processes asm/unistd.h at build-time to produce <bits/syscall.h>, which is included by <sys/syscall.h>. This will be "fixed" the next time musl is rebuilt against current kernel headers.

It matches how we include asm/unistd.h in memfd.c so we can get __NR_memfd_create, so it seems OK to me. We ought to be able to build against older musl too, not just those which are up-to-date with their kernel headers.

-- PMM

Reviewed-by on v2 1/1
#3 lore raw
In reply to Milan P. Stanić
Quoted 8 lines · Milan P. Stanić

build fails on musl libc (alpine linux) with this error:

../util/cpuinfo-riscv.c: In function 'cpuinfo_init':
../util/cpuinfo-riscv.c:63:21: error: '__NR_riscv_hwprobe' undeclared (first use in this function); did you mean 'riscv_hwprobe'?

   63 |         if (syscall(__NR_riscv_hwprobe, &pair, 1, 0, NULL, 0) == 0
      |                     ^~~~~~~~~~~~~~~~~~
      |                     riscv_hwprobe
Quoted 6 lines

../util/cpuinfo-riscv.c:63:21: note: each undeclared identifier is reported only once for each function it appears in
ninja: subcommand failed

add '#include "asm/unistd.h"' to util/cpuinfo-riscv.c fixes build

Alistair

Quoted 20 lines
---
 util/cpuinfo-riscv.c | 1 +
 1 file changed, 1 insertion(+)
util/cpuinfo-riscv.c +1 -1
index 497ce12680..8cacc67645 100644
@@ -9,6 +9,7 @@
 #ifdef CONFIG_ASM_HWPROBE_H
 #include <asm/hwprobe.h>
 #include <sys/syscall.h>
+#include <asm/unistd.h>
 #endif
 
 unsigned cpuinfo;
--

2.46.0

#4 lore raw
In reply to Milan P. Stanić
Quoted 8 lines · Milan P. Stanić

build fails on musl libc (alpine linux) with this error:

../util/cpuinfo-riscv.c: In function 'cpuinfo_init':
../util/cpuinfo-riscv.c:63:21: error: '__NR_riscv_hwprobe' undeclared (first use in this function); did you mean 'riscv_hwprobe'?

   63 |         if (syscall(__NR_riscv_hwprobe, &pair, 1, 0, NULL, 0) == 0
      |                     ^~~~~~~~~~~~~~~~~~
      |                     riscv_hwprobe
Quoted 6 lines

../util/cpuinfo-riscv.c:63:21: note: each undeclared identifier is reported only once for each function it appears in
ninja: subcommand failed

add '#include "asm/unistd.h"' to util/cpuinfo-riscv.c fixes build

Thanks!

Applied to riscv-to-apply.next

Alistair

Quoted 20 lines
---
 util/cpuinfo-riscv.c | 1 +
 1 file changed, 1 insertion(+)
util/cpuinfo-riscv.c +1 -1
index 497ce12680..8cacc67645 100644
@@ -9,6 +9,7 @@
 #ifdef CONFIG_ASM_HWPROBE_H
 #include <asm/hwprobe.h>
 #include <sys/syscall.h>
+#include <asm/unistd.h>
 #endif
 
 unsigned cpuinfo;
--

2.46.0