diff mbox series

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

Message ID 20240905150702.2484-1-mps@arvanta.net
State New
Headers show
Series [v2,1/1] util/util/cpuinfo-riscv.c: fix riscv64 build on musl libc | expand

Commit Message

Milan P. Stanić Sept. 5, 2024, 3:06 p.m. UTC
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

Signed-off-by: Milan P. Stanić <mps@arvanta.net>
---
 util/cpuinfo-riscv.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Richard Henderson Sept. 5, 2024, 7:44 p.m. UTC | #1
On 9/5/24 08:06, Milan P. Stanić wrote:
> 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
> 
> Signed-off-by: Milan P. Stanić <mps@arvanta.net>
> ---
>   util/cpuinfo-riscv.c | 1 +
>   1 file changed, 1 insertion(+)
> 
> diff --git a/util/cpuinfo-riscv.c b/util/cpuinfo-riscv.c
> index 497ce12680..8cacc67645 100644
> --- a/util/cpuinfo-riscv.c
> +++ b/util/cpuinfo-riscv.c
> @@ -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~
Peter Maydell Sept. 5, 2024, 7:57 p.m. UTC | #2
On Thu, 5 Sept 2024 at 20:44, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> On 9/5/24 08:06, Milan P. Stanić wrote:
> > 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
> >
> > Signed-off-by: Milan P. Stanić <mps@arvanta.net>
> > ---
> >   util/cpuinfo-riscv.c | 1 +
> >   1 file changed, 1 insertion(+)
> >
> > diff --git a/util/cpuinfo-riscv.c b/util/cpuinfo-riscv.c
> > index 497ce12680..8cacc67645 100644
> > --- a/util/cpuinfo-riscv.c
> > +++ b/util/cpuinfo-riscv.c
> > @@ -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.

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
Alistair Francis Sept. 6, 2024, 12:53 a.m. UTC | #3
On Fri, Sep 6, 2024 at 1:08 AM Milan P. Stanić <mps@arvanta.net> wrote:
>
> 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
>
> Signed-off-by: Milan P. Stanić <mps@arvanta.net>

Reviewed-by: Alistair Francis <alistair.francis@wdc.com>

Alistair

> ---
>  util/cpuinfo-riscv.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/util/cpuinfo-riscv.c b/util/cpuinfo-riscv.c
> index 497ce12680..8cacc67645 100644
> --- a/util/cpuinfo-riscv.c
> +++ b/util/cpuinfo-riscv.c
> @@ -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
>
>
Alistair Francis Sept. 6, 2024, 1:28 a.m. UTC | #4
On Fri, Sep 6, 2024 at 1:08 AM Milan P. Stanić <mps@arvanta.net> wrote:
>
> 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
>
> Signed-off-by: Milan P. Stanić <mps@arvanta.net>

Thanks!

Applied to riscv-to-apply.next

Alistair

> ---
>  util/cpuinfo-riscv.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/util/cpuinfo-riscv.c b/util/cpuinfo-riscv.c
> index 497ce12680..8cacc67645 100644
> --- a/util/cpuinfo-riscv.c
> +++ b/util/cpuinfo-riscv.c
> @@ -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
>
>
diff mbox series

Patch

diff --git a/util/cpuinfo-riscv.c b/util/cpuinfo-riscv.c
index 497ce12680..8cacc67645 100644
--- a/util/cpuinfo-riscv.c
+++ b/util/cpuinfo-riscv.c
@@ -9,6 +9,7 @@ 
 #ifdef CONFIG_ASM_HWPROBE_H
 #include <asm/hwprobe.h>
 #include <sys/syscall.h>
+#include <asm/unistd.h>
 #endif
 
 unsigned cpuinfo;